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

Min Property

Program gif also shows a recursive implementation of the Min property get accessor 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 accessor follows directly from that of the Find method. The worst case running time of Min is O(n) and the average running time is tex2html_wrap_inline59121, where n is the number of internal nodes in the tree.


next up previous contents index

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