Revise Node and LinkedBag as described in Segment 3.29.
Searching a binary search tree. The organization of the nodes in a binary search tree enables us to search the tree for a particular data object, given its search key. For example, suppose that we search the tree in Figure 23-18 for the string Jim. Beginning at the root of the tree, we compare Jim with Jared. Since the string Jim is greater than the string Jared, we search the right subtree of the root. Comparing Jim to Megan, we find that Jim is less than Megan. We search Megan’s left subtree next and find Jim.
To search for Laura, we would compare Laura with Jared, then with Megan, and then with Jim. Since Laura is greater than Jim, we would search Jim’s right subtree. But this subtree is empty, so we conclude that Laura does not occur in the tree.
We can express our search algorithm recursively: To search a binary search tree, we search one of its two subtrees. The search ends when either we find the item we seek or we encounter an empty subtree. We can formalize this search by writing the following pseudocode:
Algorithm bstSearch(binarySearchTree, desiredObject)// Searches a binary search tree for a given object.// Returns true if the object is found.if (binarySearchTree is empty)return falseelse if (desiredObject == object in the root of binarySearchTree)return trueelse if (desiredObject
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.