Rara’s seed list grows as a vine on the pergola: words that start alike share branches, type a prefix and its walk lights up, its cost compared to a real…
Why it matters
Autocomplete, prefix search, spell-check dictionaries, IP routing tables: all need "which words start with this?" fast. A trie answers in steps as long as the prefix, however big the dictionary.
The key idea
Finding a prefix is a walk as long as the prefix, not a check of every word
Common mistakes
Autocomplete gets slower once the dictionary grows to millions of words An array + startsWith is O(word count) per keystroke. A trie is O(prefix length), whatever the dictionary’s size: use a trie or a radix tree.
A trie eats RAM though only a few words are alike Every node carries its own map of children, so a naive trie wastes memory on words that rarely share prefixes. A radix tree merges chains of single-child nodes into one edge.
A short word is lost though inserted, because a longer word runs along its path That is a missing end flag (akhir, end) at the node where the word stops. Mark word ends explicitly; do not take "no children" to mean a word ends.
Try it in this playground
Type a prefix Suggestions narrow letter by letter: saw gives sawi, sawit, sawo.
Plant a word that rides along A word that shares a prefix grows only its remaining letters.
A prefix with no branch Type a prefix that breaks off: the search stops at the first missing letter.
A word lost to the leaf check Use the "no children" check with sawi and sawit.