trie
•
○ = node · ◎ ringed = end of a word
Concept
▸1node = { children: map<char,node>, isWord }2insert(word):3 cur = root4 for ch in word:5 if ch not in cur.children:6 cur.children[ch] = new node7 cur = cur.children[ch]8 cur.isWord = true910search(word): walk; true if path exists11 AND the final node.isWord12// shared prefixes ⇒ stored once
state
- structureprefix tree