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
|
|
(define in?
(lambda (elt tree)
(cond
((empty-tree? tree) #f)
((= elt (root tree)) #t)
((< elt (root tree))
(in? elt (left-subtree tree)))
(else
(in? elt (right-subtree tree))))))
|