previous | index | next

Determining If an Element Is In a BST

Compare looking something up in:

Dictionary Binary Search Tree
1. If you've searched the
whole book, give up.
If the tree is empty,
return false.
2. If not, open to middle. If not, look at root.
3. Word found? Element = root?
4. If so, you're done.
If not, is word in
left half?
If so, return true.
If not, is element < root?
5. If so, search left half.
If not, search right half,
If so, search left subtree.
If not, search right subtree


previous | index | next