Words: "apple" (a→p→p→l→e*), "ape" (a→p→e*), "bad" (b→a→d*). * marks word end.
Search for "ape" in a trie containing "apple" and "ape". Each cell is one character in the query — traverse the trie char by char, O(L) total regardless of dictionary size.
🧠 Under the Hood — shared prefixes are stored once
A trie is a tree where the path spells the key — the node itself stores almost nothing. That's why prefix operations are free: all words starting with "ap" live in exactly one subtree, so autocomplete is "walk L nodes, then DFS the subtree". A hash set scatters related keys uniformly (by design!), destroying prefix locality — great for exact membership, useless for enumeration.