Question: In Java Create a client class that does the following: - Manually creates an instance of a binary expression tree that represents the following expression:

In Java Create a client class that does the following:

- Manually creates an instance of a binary expression tree that represents the following expression:

- ( 2 + 9 ) + ( 7 - ( 3 * 8 ) )

- Do this by using methods such as addRoot, addLeft, addRight, set, and attach.

- The element should be of type String

- Note that you are manually building this specific expression tree, the pseudo code might look something like:

o Create a LinkedBinaryTree with 2 as its root element.

o Create another LinkedBinaryTree with 9 as its root element.

o Create a third LinkedBinaryTree with + as its root element.

o Attach the tree with the 2 as the left child and the tree with the 9 as the right child to the tree with the +.

o You now have a subexpression that can be attached to the expression tree as you build it.

o etc.

The above example implies a bottom-up construction of the tree. You may want to consider if it would be easier to build the tree in a top-down fashion or in a bottom-up fashion.

Once you have created the expression tree have your client print out the following:

- The literal string that represents the expression, i.e.:

( 2 + 9 ) + ( 7 - ( 3 * 8 ) )

- The height of the expression tree

- The preOrder traversal of the tree

- The inOrder traversal of the tree

- The postOrder traversal of the tree

- The breathFirst traversal of the tree

- The parenthesized representation of the tree using Eulers Tour

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!