Question: The third programming project isvolves writing a program to read in the prooder acpresentatios of a bisory tree and determine whether it is a balansed
The third programming project isvolves writing a program to read in the prooder acpresentatios
of a bisory tree and determine whether it is a balansed binary search tree. Given the bieary tree
shown below:
asterisks represent null children.
The program should repeatedly prompt the user for a binary tree. It should thes display the tree
using indestation. For the above tree, is iderted representation woukd be as follows:
It slould then casegorise the binary tree in one of three ways
Ir is not a binary search tree
: It is a balanced bisary search tree
It is a bisary searcla tree bat it bis sot balabeed
If the tree is an a balanced binary search tree, a binary search tree coetaining the same set of
values should be corstructed and displayed in the iskented format down above It is nos
values should be constructed and displayed a the bdested format bown above. It is not expesited that the existing tree be retalanced, jost that a new tree with the same set of values be
constrocted. Thes the beight of the original tree and the batased binary search tree should be
displayed.
Showas below bi a sample sessioe that involves each of the above cases:
It
warch tree but it ia not halanced
Origlinal tree han leight Ralanced tree han belght
It in not a binazy wesch tree
In ablition, the program should verify that the tree input has valid syntac. Eack of the following
I a calition, the program shy erress slould be detected,
Incomplese Tree
Duata is Not an lnteger
Exra Characters at the End
Missing Left Parenthesis
The program should consibt of three clases. The first class slould be the class that defines the
binary tree. It should be an immatable class with the following public methods:
A coestructor that accepts a string coesaining the peconder representatice of a bieary tree
and construcs a bieary tree
A coestructor that accepts an array list of integers and constructs a balanced binary search
tree containing those values
A mestad that outpuss the biary tree in indented form
A melbod that ecturs whether the tree is a binary searcls tree.
A mellod that returs whether the tree is balanced
A melbod that returses the beiglt of the tree
A method that returas in array list of the values in the tree
Additional private methods may be added as needed.
The second claws slould be a class that defines a clocked exception that is throw: when a tree
with ivvalid syntax is isput. The thisd class is the class that coetains the main method and
accepts the user input and displays the mouls:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
