Ryan Knopp
← Back to Searches

Trie Search

A trie (often pronounced “try”, from retrieval) is a tree built for strings. Instead of each node holding a full word, each node represents a single character, and words are formed by tracing paths down from the root. Words that start with the same letters share the same ancestral path: “cat”, “car”, and “cart” all branch off the same “c-a” trunk.

That structure gives the trie its superpower: search time does not depend on the number of words in the dictionary. Whether the trie holds fifty words or fifty million, looking up a five-letter word takes at most five steps down the tree—O(k) where k is word length. If any letter’s transition branch is missing, the search halts immediately: the word cannot exist. When all letters match, the algorithm simply checks whether the final node is flagged as a complete word (marked with an asterisk) or merely a prefix to longer words.

This prefix-sharing design is why tries are the bedrock of text autocomplete, spell checkers, IP routing tables, and predictive keyboard search. The trade-off is memory: pointers for every possible branching character can consume significant space compared to a flat array or hash table.

Watch the gold path trace letter by letter down the tree branches, and see how quickly it determines whether a string is a complete word, a prefix, or absent entirely. Use the Word dropdown up top to choose from words stored in the trie (such as cat, cart, or dove), test prefixes that aren’t full words (ca), or see missing branches reject nonexistent words (card, bat). You can also type any custom word into the search box.