Type "comp" into a search box and, before you finish the word, a list appears: computer, complexity, complete, compress. The machine just sifted a dictionary of perhaps a million entries — and it did it faster than you could blink. How?
The trick is an old, elegant data structure called a trie (from retrieval, usually said "try"). Instead of storing each word as a separate string, a trie stores words letter by letter along shared paths. Every word that begins with "comp" walks the same first four steps; only where the words differ does the path branch.
That single idea — let common prefixes share one road — is why looking something up costs time proportional to the length of your query, not the size of the collection. This is not an open problem or a deep mystery. It is one of computer science's quietly solved wins, and once you see it you spot tries everywhere.
Comments
Loading comments...