Strings & Compression Hard
Trie Prefix Autocomplete
Follow recursive trie insertion, then use breadth-first search to return the shortest matching word.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
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.
Current operation
Trace stateReady 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
JavaAutoCompleter.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