Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Constructor and getM Methods

Program gif defines the constructor and getM methods 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 getM method shown in Program gif 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 getM method is clearly O(1).


next up previous contents index

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