Question
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
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