What you're building
A Trie (prefix tree) β a tree where each node represents one character, and every path from root to a marked leaf spells out a word. Tries power:
- Search box autocomplete (Google, VS Code)
- Spell-checkers
- IP routing tables
- Autocorrect on your phone keyboard
Requirements
insert(word)β add a word to the triesearch(word)β returntrueif the exact word was insertedstartsWith(prefix)β returntrueif any inserted word begins withprefixautocomplete(prefix)β return an array of all inserted words that start withprefix(any order, max 10 results)
Stretch goals
- Add a
delete(word)method that removes a word without breaking other words sharing its prefix - Weight words by insertion frequency and return
autocompleteresults sorted by frequency
What this proves
You can implement tree traversal, recursive DFS, and understand a core data structure used in production search infrastructure.
β‘ 50 XP
solution.jsRuns in your browser
Loading editorβ¦
Tests4 to pass
search finds inserted words
startsWith prefix matching
autocomplete returns all words with prefix
autocomplete returns empty for unknown prefix
Run your code to check these.