The NaryTree class declares two constructors. Implementations for the two constructors are given in Program . The first constructor takes a single argument of type unsigned int which specifies the degree of the tree. This constructor creates an empty tree. It does so by setting the key pointer to zero, and by setting the length of the subtree array to zero. The running time of this constructor is O(1).
Program: NaryTree Class Constructor Definitions
The second constructor takes two arguments. The first specifies the degree of the tree, and the second is a reference to an Object instance. This constructor creates a non-empty tree in which the specified object occupies the root node. According to Definition , every internal node in an N-ary tree must have exactly N subtrees. Therefore, this constructor creates and attaches N empty subtrees to the root node. The running time of this constructor is O(N), since N empty subtrees are created and constructed and the constructor for an empty N-ary tree takes O(1) time.