Binary tries
-
Binary tries are binary trees
-
Unlike a BST or DST, in a binary trie, only leaf nodes hold keys
-
However, like a DST, search in a binary trie is guided by comparing keys one bit at a time (radix search with radix 2)
-
The basic search algorithm to find
key
in a binary trie:
1. Set currentNode = root, i = 0.
2. If currentNode is null, or i > # of bits in key,
return "not found".
3. If currentNode is a leaf, and i == # of bits in key,
return "found".
4. Look at the value of the ith bit in key. If 0,
set currentNode = currentNode.left; else
set currentNode = currentNode.right
5. Set i = i+1 and Go to 2.
-
The basic insert algorithm in binary tries is straightforward. (Use find algorithm to find where the key must go, if it is to be found later! And put it there.)
CONTENTS PREVIOUS NEXT