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

Implementation

Program gif introduces the MWayTree class. The MWayTree class extends the abstract SearchTree class introduced in Program gif. The two instance attributes, _key and _subtree, correspond to the components of a node shown in Figure gif. (Remember, the _count instance attribute is inherited from the abstract Container base class introduced in Program gif).

   program20822
Program: MWayTree class __init__ method and m property

The first instance attribute, _key, is an array used to record the keys contained in the node. The second instance attribute, _subtree, is an array of MWayTree instances which are the subtrees of the given node.

The inherited _count instance attribute keeps track of the number of keys contained in the node. Recall, a node which contains tex2html_wrap_inline64737 keys has tex2html_wrap_inline64739 subtrees. We have chosen to keep track of the number of keys of a node rather than the number of subtrees because it simplifies the coding of the algorithms by eliminating some of the special cases.


next up previous index

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