adding trie diagram

This commit is contained in:
Jidong Xiao
2023-12-04 16:07:05 -05:00
parent 9390592f0e
commit 508c7754cb

View File

@@ -82,9 +82,10 @@ smaller coefficient), require less total memory, and work better in parallel. Or
- In a trie or prefix tree, the key is defined not by storing the data at the node or leaf, but instead by the path to - In a trie or prefix tree, the key is defined not by storing the data at the node or leaf, but instead by the path to
get to that node. Each edge from the root node stores one character of the string. The node stores the value get to that node. Each edge from the root node stores one character of the string. The node stores the value
for the key (or NULL or a special value, e.g., -1, if the path to that point is not a valid key in the structure). for the key (or NULL or a special value, e.g., -1, if the path to that point is not a valid key in the structure).
- Lookup in the structure is fast, O(m) where m is the length (# of characters) in the string. A hash table has
similar lookup (since we have to hash the string which generally involves looking at every letter). If m << n, ![alt text](trie.png "trie")
we can say this is O(1).
- Lookup in the structure is fast, O(m) where m is the length (# of characters) in the string. A hash table has similar lookup (since we have to hash the string which generally involves looking at every letter). If m << n, we can say this is O(1).
## 27.7 Trie / Prefix Tree - Discussion ## 27.7 Trie / Prefix Tree - Discussion