Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help creating a Java m-ary tree node class: Class Name: MTreeNode Instance variables: 1. AnyType element 2. int m 3. ArrayList children Constructors

I need help creating a Java m-ary tree node class:

Class Name: MTreeNode

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

Constructors: 1. public MTreeNode (AnyType element, int m, ArrayList children) 2. public MTreeNode (AnyType el, int m) where 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, and an array containing a total of m or less children.

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 shown 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

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe the team dynamics at Facebook.

Answered: 1 week ago