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 (BST)and provides a range of operations to test understanding of data structures, recursion, and traversal techniques. Requirements 1.Class Definition (20pts)Define a class `BST`to represent the binary search tree. Include an inner class `Node`to store the value, left child, and right child. 2.Core BST Operations (20pts)Implement the following methods: -void insert(int value): Adds a value to the BST.Ensure that duplicates are not allowed. -boolean search(int value): Returns `true`if the value exists in the tree, `false`otherwise.-void delete(int value): Removes a node from the BST while preserving the tree structure. 3.Traversal Methods (20pts)Implement methods for di]erent 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 level-order traversal (BFS)as a list. 4.Additional Operations (20pts)Implement the following methods to enhance the BST functionality: -int height(): Returns the height (or depth)of the tree. -int minValue(): Returns the smallest value in the BST.-int maxValue(): Returns the largest value in the BST.-boolean isBalanced(): Checks if the BST is height-balanced (di]erence in height between left and right subtrees of any node is at most 1).-void printPaths(): Prints all root-to-leaf paths. 5.Testing (20pts)Write a `main`method to test the BST.Perform 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 root-to-leaf paths

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 Programming Questions!