Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

FindMin Member Function

Program gif also shows a recursive implementation of the FindMin member function of the BST 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 routine follows directly from that of the Find function. The worst case running time of FindMin is O(n) and the average running time is tex2html_wrap_inline59891, where n is the number of internal nodes in the tree.


next up previous contents index

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