

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: Tries
incomplete
2: Exists
incomplete
3: Prefix Matching
incomplete
4: Words With Prefix
incomplete
5: Find Matches
incomplete
6: Find Matches Review
incomplete
7: Longest Common Prefix
incomplete
8: Advanced Find Matches
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Tries tend to be most useful for prefix matching. For example, if you wanted to find all the words in a dictionary that start with a given prefix, a trie works great! Autocomplete, keyword search, and spellcheck are all good examples of where a trie can be useful.
Remember, a hash table is only good for exact matches, whereas a trie allows you to look up all of the words that match a given prefix. For example, given this trie:
{
"h": {
"e": {"l": {"l": {"o": {"*": True}}, "p": {"*": True}}},
"a": {"r": {"d": {"*": True}}},
}
}
We could quickly find all the words that start with "hel" and get: