Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 0 1 6 MSISS Q QUESTION 3 PARTA: The following class represents nodes of a binary tree, which stores String objects. public class Node
MSISS Q
QUESTION
PARTA:
The following class represents nodes of a binary tree, which stores String objects.
public class Node
public String key; public Node left; public Node right;
NodeString key, Node left, Node right
this.key key; this.left left; this.right right;
i
A binary tree is either empty represented as a null reference or it has a root which
is a Node object, whose left and right fields point to two disjoint binary trees.
The following method prints by level all the keys in a binary tree.
public void printByLevelNode rcot
The argument of the method is the root of the tree. The output of the method should
contain the keys of the tree, by level. This means that it first prints the root Level
then the keys in children nodes of the root Level then all keys in children of
children of the root Level etc.
The relative order of keys within each level is not important. Whitespace and
separators between keys are also not important. You may assume that all strings in
the tree are not null.
Examples:
Output: ABCDEFGHIJto be or not to be
Implement the above method in Java so it has the most efficient worstcase
asymptotic running time. You should justify your answer.
You can use any of the standard generic Abstract Data Types ADTs:
Where Comparable is the following generic Java interface:
int compareToT o Compares this object with the specified object o It returns
a negative number if this is less than o a positive number
if this is greater than o and zero if this is equal to
You do not need to implement the ADTs you use, but for each one you use you
should specify:
An AP of the ADT, containing the methods you use in your implementation.
Atight upper bound of the worstcase asymptotic running time of each of the
ADT methods.
The name of a known implementation of the ADT that has the running time
properties you specified above.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started