|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
Program
introduces the MWayTree class.
The MWayTree class extends the abstract SearchTree class
introduced in Program
.
The two instance attributes, _key and _subtree,
correspond to the components of a node shown in Figure
.
(Remember, the _count instance attribute is inherited from the
abstract Container base class introduced in
Program
).

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
keys
has
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.