306 Chapter 9 Abstract Data Types and Algorithms With each comparison, either we find the item or cut the tree in half by moving to search in the left subtree or the right subtree. In half? Well, not exactly. As shown in Figure 9.17, the shape of a binary tree is not always well balanced. Clearly, the efficiency of a search in a binary search tree is directly related to the shape of the tree. How does the tree get its shape? The shape of the tree is determined by the order in which items are entered into the tree. Let’s build a binary search tree. Building a Binary Search Tree The clue of how to build a binary search tree lies in the search algorithm we just used. If we follow the search path and do not find the item, we end up at the place where it would be if it were there . Let’s now build a binary search tree using strings: john , phil , lila , kate , becca , judy , june , mari , jim , and sarah . Because
This is the end of the preview.
access the rest of the document.