Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java You are to create a class named BinaryTree. This will simulate a balanced and ordered binary tree. You also need to create a

Use Java

You are to create a class named BinaryTree. This will simulate a balanced and ordered binary tree. You also need to create a TreeNode class, which defines the data contained in each node of the tree. In this case, it is an integer. Remember that the node also needs a way to track back to its parent, as well as its left and right children. For the purpose of this assignment, each node should also contain an indication of its level within the tree. For the TreeNode, the constructor only needs to obtain the integer value held in the node. The class should have modifiers to allow its placement on the tree; in other words, the ability to connect it to its parent and connect child nodes. Also have a modifier to change the level. The BinaryTree class constructor will not receive any input. The class will have three methods: add, remove, and find:

? Add(int) receives an integer value, creates the new TreeNode, and adds it to the appropriate location on the tree, keeping it balanced. Use the algorithm available in the Web Links for assistance.

? Remove(int) locates the desired value and removes it from the tree, balancing it afterwards. If the node does not exist, it does nothing. Use the algorithm available in the Web Links for assistance.

? Find(int) receives the integer value desired, and returns the TreeNode of that item. It returns NULL if the item is not located. Note you may need some other Private methods (like rotate()) in order to keep the tree in balance.

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_2

Step: 3

blur-text-image_3

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago