Coral Prefix Grove
The reef guide has thousands of creature names. Grow a branching letter tree so divers can find every matching name without checking the whole ocean.
π§ Before we start
At the oasis, you kept one safe queue for many caravans. Today, many words share one path. A trieβsaid βtryββstores one letter per branch, reuses shared beginnings called prefixes, and marks where each complete word ends.
Grow FIN, then FISH
Tap the next letter for each word. When FISH arrives, do not regrow F and Iβfollow their shared path, then branch.
Ask for every βCOβ¦β name
Build the prefix path C β O. The trie can then collect only the words below that branch.
Race to TUNA
Compare two strategies. A full scan checks names one by one. A trie follows exactly one letter branch at each step.
π Full list scan
Inspect COD, CORAL, COWRIE, EEL, FIN, FISH, RAY, then TUNA.
πΏ Trie path
Follow T β U β N β A. Unrelated branches are never visited.
Debug the missing word end
STAR is stored, and ST uses the same path. But ST is a complete word too. Without an end marker at T, the trie thinks ST is only an unfinished prefix.
βnot foundβ
π What you learned
- A trie stores words as branching paths of letters.
- Words with the same prefix reuse the same beginning path.
- A prefix query jumps to one branch, then collects the words below it.
- Direct letter paths skip unrelated names during search.
- A word-end marker separates a complete word from a prefix that merely continues.