e
called a binary search tree. These are identical to binary trees but have the additional constraint that the data on the left branch of a node must be less than the data in the node. Likewise, the data on the right branch of the node must be greater than the data held in the node. All the following binary trees are also binary search trees.
m
pl
Unlike stacks and queues, there is a range of different ways to traverse binary tree data structures. Each method will return a different set of results, so it is important that you use the correct one.
Figure 1.7 A binary tree.
D
ra
ft
sa
We’ll use the binary search tree shown in Figure 1.7 to demonstrate the different methods of traversal.
Pre-order traversal (depth first search): Start at the root node, traverse the left sub-tree, then traverse the right sub-tree. This would give: D B A C F E G. In-order traversal: Traverse the left sub-tree, then visit the root node, and finally traverse the right sub-tree. This would give: A B C D E F G.
"******ebook converter DEMO - www.ebook-