Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Implementing Search Trees

Since search trees are designed to support efficient searching, it is only appropriate that they extend the SearchableContainer class. Recall from Section gif that the searchable container class includes the operations __contains__, find, insert, and withdraw.

   figure18605
Figure: Object class hierarchy

Program gif defines the SearchTree class. The abstract SearchTree class extends the abstract Tree class introduced in Program gif as well as the and the abstract SearchableContainer class defined in Program gif.

   program18619
Program: Abstract SearchTree class min and max properties.

In addition, two properties are defined--min and max. The min property uses the getMin method to return the object contained in the search tree having the smallest key. Similarly, the max uses the getMax method to returns the contained object having the largest key.




next up previous index

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