*This preview shows
page 1. Sign up
to
view the full content.*

**Unformatted text preview: **after the contents of any nodes in its left
subtree We need the nodes of the tree to have some
property of order.
This is called a binary search tree.
binary Consider the data values
0, 2, 5, 6, 7, 8, and 9
These are all binary trees with this data.
0 binary
search
tree
0 2 • comes before the contents of any nodes in its
before the contents of any nodes in its
right subtree
Again, we'll use a comparison function to
determine the order. 5
6 Thus, we start at the root, testing the value we're
seeking against each node's value. 6 7 9
6
7 5
8 0 However, the resulting tree is not unique. Each node in the tree essentially divides its
descendants into two groups: those whose
values go before the node value (they in the
values go before the node's value (they're in the
left
left subtree), and those whose values go after the
node's value. 8 5 2 9 Before we discuss how to build binary search
trees, we'll show how to find a value in one. 7 8 9 2 If
If the value we seek goes before the current
node's value, we go left.
Otherwise we go right.
We then treat the subtree the...

View
Full
Document