David Anderson
Recurse Center W1 '16
Simplest implementation.
Key is single value of the alphabet.
Each node has R children, where R is the number of possible values (null nodes not pictured).
Can be costly for space complexity (think Unicode - 65, 536-way Trie!)
| Operation | Returns | Description |
|---|---|---|
| put(key, val) | N/A | add a new value for given key |
| get(key) | value | retrieve value paired with key |
| delete(key) | N/A | delete key and corresponding value |
| keys() | iterable of keys | all keys |
| keysWithPrefix(s) | iterable of keys | keys having s in the beginning |
| keysThatMatch(s) | iterable of keys | keys that match s (wildcards possible) |
| longestPrefixOf(s) | key | longest key that is a starts with s |
| implementation | search hit | search miss | insert | space (references) |
|---|---|---|---|---|
| red-black BST | L+ c lg^2 N | c lg^2 N | c lg^2 N | 4 N |
| hasing (linear probing) | L | L | L | 4N to 16N |
| R-way trie | L | logR N | L | (R + 1) N |
| TST | L + ln N | ln N | L + ln N | 4 N |
| TST w/ R^2 Root | L + ln N | ln N | L + ln N | 4 N + R^2 |