Codele / Data structures
Tries
When you type on a phone, it suggests words after only a few letters. It keeps its words in a tree where each step down adds one letter.
- A trie is a tree where each step down adds one letter.
- Words that start the same share a path. Cat and car share c and a.
- To find suggestions, walk only the letters typed, then read the words below that spot.
- In code each stop is a dictionary of letters, and each letter leads to the next dictionary.
- If a letter has no branch, no stored word starts that way.
Loading the playable lesson…