Question: I am trying to create a m-ary tree node class. A rooted tree is an m-ary tree if every internal node has no more than

I am trying to create a m-ary tree node class. A rooted tree is an m-ary tree if every internal node has no more than m children.

I cannot: 1) Cannot use any built in Java Collections Framework classes anywhere in your program (e.g. no ArrayList, LinkedList, HashSet, etc.) 2) Cannot Add additional public methods or variables to MTreeNode

An outline of the class is given below:

Class Name: MTreeNode

Instance variables: 1. AnyType element 2. int m 3. ArrayList children

Constructors: 1. public MTreeNode (AnyType element, int m, ArrayList children) --element represents values or elements of type AnyType -- m is the branching factor which is 3 in 3-ary trees and 4 in 4-ary trees --children is an array containing a total of m or less children.

2. public MTreeNode (AnyType el, int m) --e1 represents values or elements of type AnyType -- m is the branching factor which is 3 in 3-ary trees and 4 in 4-ary trees

Methods: 1. public static int height(MTreeNode> t) --returns the height of the tree rooted at t and -1 if null

2. public static int size(MTreeNode> t) --returns the size of the tree rooted at t and 0 if null

3. public boolean addChild(MTreeNode child) --adds the child to the list of children; returns true if child is added, false if the array is full thus cant add more children

4. public String toStringPreOrder() --returns a String representation of a pre-order walk on the m-ary tree rooted at this node.

5. public String toStringPostOrder() --returns a String representation of a post-order walk on the m-ary tree rooted at this node.

6. public String toStringLevelOrder() returns a String representation of a level-order walk on the m-ary tree rooted at this node. Hint: Use a queue.

All walks are from right to left as compared to the traditional left to right.

Example Outputs of tree traversals on the m-ary tree given on the below: Pre-order: A D F L K E C B I J H G Post-order: L K F E D C J I H G B A Level-order: A D C B F E I H G L K J

Height of the tree = 3 Size of the tree = 12

I am trying to create a m-ary tree node class. A rooted

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!