I. What is Trie
Trie is an efficient information reTrieval data structure.
- search complexities can be brought to optimal limit (key length).
- If we store keys in BST, a well balanced BST will need time proportional to
O(M*log N)
, whereM
is maximum string length, andN
is number of keys in tree - Using Trie, we can search the key in
O(M)
time.
II. Use case
- Prefix matching
- Check if a word exists in a dictionary
- Word frequency in dictionary
- Sort Words in dictionary
III. Implementation
1 | /* |