DSAVisualiseData Structures & Algorithms Studio
Strings & Compression Hard

Trie Prefix Autocomplete

Follow recursive trie insertion, then use breadth-first search to return the shortest matching word.

Trace input

Bounded JSON

Edit the lesson input, then build a deterministic source-linked trace.

This lesson validates its own input and operation limits.

Source scenarios

Complexity

BestO(|prefix|)
AverageO(total dictionary letters + R × visited nodes)
WorstO(total dictionary letters + R × trie nodes)
SpaceO(trie nodes + queue)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Given lowercase dictionary words and a prefix, return the shortest word beginning with that prefix; ties go to the lexicographically smallest word.

  • Returning the first inserted matching word instead of the shortest one.
  • Scanning children in dictionary insertion order instead of ascending letter order on ties.
  • Forgetting that a prefix which is itself a key is returned immediately.

Algorithm code

Java
AutoCompleter.java (pinned repository source)Step linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1