Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java, you are to implement a Binary Search Tree (BST) of integers (with no duplicate) where each node contains: (1) an integer value; (2)

Using Java, you are to implement a Binary Search Tree (BST) of integers (with no duplicate) where each node contains: (1) an integer value; (2) reference to the left child; (3) reference to the right child; and (4) a reference to the nodes parent (you may consider that the parent of the root is equal to null). Recall that a BST has the property that for every node in the tree, the value of any node in its left sub-tree is less than the value of the node, and the value of any node in its right sub-tree is greater than the value of the node.

Add the following methods to your BST:

add(int element): this method adds a node with value element into the BST

int leaves(): this method returns the number of leaves in the tree

List getPath(int value): this method returns the path from the specified value to the root. Your method should take time proportional to the height of the tree

int rangeCount(int leftValue, int rightValue): this method returns the number of elements in the BST that are between leftValue and rightValue. You may assume that both leftValue and rightValue exist in the tree

void toReverse(): this method modifies the BST into a reverse BST. A reverse BST has the property that for every node in the tree, the value of any node in its left sub-tree is greater than the value of the node, and the value of any node in its right sub-tree is less than the value of the node. Note, in all the other methods you can assume that the tree is a BST.

Write a main method that tests your implementation. Note, you can add any other helper methods to simply your implementation.

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions