Question: Create a Java program that implements a Binary Search Tree ( BST ) and provides a range of operations to test understanding of data structures,
Create a Java program that implements a Binary Search Tree BSTand provides a range of operations to test understanding of data structures, recursion, and traversal techniques. Requirements Class Definition ptsDefine a class BSTto represent the binary search tree. Include an inner class Nodeto store the value, left child, and right child. Core BST Operations ptsImplement the following methods: void insertint value: Adds a value to the BSTEnsure that duplicates are not allowed. boolean searchint value: Returns trueif the value exists in the tree, falseotherwisevoid deleteint value: Removes a node from the BST while preserving the tree structure. Traversal Methods ptsImplement methods for dierent tree traversals: void inorderTraversal: Prints nodes in ascending order. void preorderTraversal: Prints nodes in preorder. void postorderTraversal: Prints nodes in postorder. List levelOrderTraversal: Returns the levelorder traversal BFSas a list. Additional Operations ptsImplement the following methods to enhance the BST functionality: int height: Returns the height or depthof the tree. int minValue: Returns the smallest value in the BSTint maxValue: Returns the largest value in the BSTboolean isBalanced: Checks if the BST is heightbalanced dierence in height between left and right subtrees of any node is at most void printPaths: Prints all roottoleaf paths. Testing ptsWrite a mainmethod to test the BSTPerform the following: Insert a series of values and print the BST in all traversal orders. Search for a value that exists and one that does not. Delete a few values, including a leaf node, a node with one child, and a node with two children. Check the height, minimum, and maximum values. Test if the tree is balanced and print all roottoleaf paths
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
