Patterns
T · Pattern 14
Trie
A tree where each node represents a character. Enables O(m) prefix searches (m = word length) instead of O(n·m) linear scan through all words.
- Time
- O(m) per operation
- Space
- O(n · m)
Spot it when
- Autocomplete / prefix search
- Word dictionary with wildcard search
- Word search II (multiple words in grid)
- Longest common prefix