Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Program defines the constructor and the M property of the MWayTree class. The constructor takes a single, integer-valued argument that specifies the desired value of M. Provided M is greater than or equal to two, the constructor creates two arrays of length M. Note, a node in an M-way tree contains at most M-1 keys. In the implementation shown, key[0] is never used. Because the constructor allocates arrays of length M, its worst-case running time is O(M).
The M property shown in Program provides a get accessor that returns the value of M. That is, it returns the maximum number of subtrees that a node is allows to have. This is simply given by the length of the subtree array. The running time of the accessor is clearly O(1).