A trie stores characters in a tree; each path from root corresponds to a prefix.
Each node holds a map of children and a boolean end.
insert: create nodes along the word path and mark the last node as end.search: follow the path and require end at the end.startsWith: follow the path only.Common prefixes share nodes, making prefix queries efficient.
A trie stores characters in a tree; each path from root corresponds to a prefix.
Each node holds a map of children and a boolean end.
insert: create nodes along the word path and mark the last node as end.search: follow the path and require end at the end.startsWith: follow the path only.Common prefixes share nodes, making prefix queries efficient.