Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

findMin Method

Program gif also shows a recursive implementation of the findMin method of the BinarySearchTree class. It follows directly from the data ordering property of search trees that to find the node containing the smallest key in the tree, we start at the root and follow the chain of left subtrees until we get to the node that has an empty left subtree. The key in that node is the smallest in the tree. Notice that no object comparisons are necessary to identify the smallest key in the tree.

The running time analysis of the findMin method follows directly from that of the find method. The worst case running time of findMin is O(n) and the average running time is tex2html_wrap_inline58840, where n is the number of internal nodes in the tree.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.