Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Program 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 , where n is the number of internal nodes in the tree.