Example 1
Consider the following binary search tree in which names are used as keys.
To search for Betsy in this tree, we begin by looking at the root, comparing
Betsy to Humie. Since Betsy precedes Humie, and all keys that are less
than Humie are in the left subtree, we move to the left subtree. We continue
the process by comparing Betsy to Angela and moving to Angela's right
subtree, comparing Betsy to Dan and moving to Dan's left subtree, where
we finally find Betsy.
If we attempted a search for an item that was not in the tree, then the
process outlined here would eventually reach a dead end by following a
path to an empty subtree. For example, a search for Tina would lead us
to Burnie, Philip, and Thomas. Since the right subtree from Thomas is
empty, the search ends in failure.
|