Question: CSC 220 Data Structures Program 6 (follows: L8.1 - Binary Search Trees) Your objective is to implement the main operations of a binary search tree


CSC 220 Data Structures Program 6 (follows: L8.1 - Binary Search Trees) Your objective is to implement the main operations of a binary search tree from the lecture. To be clear, this entails creating a class for your tree nodes, then creating another class for your binary search tree. Create a class called Node (this is different from your Linked List Node class) that has three fields: a field called left for the left child link, a field called rlght for the right child link and a field called dat a for the int data being held. These fields should be private with public accessors and mutators fi.e. getletc, getRight, getData, setLett, setRight and set.Data). This Node class can either be a public class in its own file (i.e. Node java) or a class without the public keyword in the same file as your BST class (described below). Create a public class called BST (and put it in a file called BST.java) that has the following: - Fields public field called root that points to the root of the tree. This must be public for the visualization to work Any other fields you need - Public methods A default constructor (i.e. a constructor that doesn't take any parameters). This will initialize root to null. insert (value) - Takes an int as input and inserts it into the logical place in the tree - You don't have to worry about duplicate values (see 'Edge Cases and Notes' for more information) - You may use either recursion or iteration here. search (value) - This method takes an int as input and returns true if the given value is in the tree, false otherwise. You don't have to retum the location in the tree, just a boolean indicating whether the value is found. - If root is null, you should retura false (since the value could not be found) - You may use either recursion or iteration here. delete (value) - This method takes an int as input, searches for it in the tree and deletes it according to the method described in the nodes. - If the value given is not found or if the root is null, this operation does nothing - Do NoT even attempt this method untili everything else works! - You may use either recursion or iteration here. 1 min() - Returns the smallest value in the tree. - If the root is null, return-1 - You may use either recursion or iteration here. max() - Returns the largest value in the tree. - If the root is null, return-1 - You may use either recursion or iteration here. inorder () - Traverses the tree according to the inorder traversal described in the notes. - Do not print values. Instead, construct a String, concatenating the node values as they are processed with either a comma or a space in between values. Return this 5 tring. - If the root is null, retum an empty string (i.e. " with nothing in between the quotes) - You must use recursion here. preorder () - Traverses the tree according to the preorder traversal described in the notes. - Do not print values. Instead, construct a String. concatenating the node values as they are processed with either a comma or a space in between values. Return this String. - If the root is null, return an empty string (i.e. =m with nothing in between the quotes) - You must use recursion here. postorder() - Traverses the tree according to the postorder traversal described in the notes. - Do not print values. Instead, construct a String, concatenating the node values as they are processed with either a comma or a space in between values. Return this String. - If the root is null, return an empty string (i.e. " with nothing in between the quotes) - You must use recursion here. idge Cases and Notes: ou do not have to use generics for this. For this assignment, just use int as the data type for the data tored in your binary search tree nodes. Do not worry about handling duplicate values, You can safely assume that I will not attempt to store the iame value twice in your tree, so your tree does not have to handle this situation. very function should handle the case where the root is null. See the function description above for nstructions on how to handle it for that function. fou may use helper functions to help you with the recursion. For example, you could have a public inorder method (i.e. public String inorder ()) that simply calls a private inorderRecursive method (L.e. private String inorderRecursive (Node cur)) and iends it the root node to start the inorder traversal (Le. I notderfiecursi ve (root)). This is helpful ince this means a developer using your tree class would only need to call tree. . norder (). issuming they have a BST object named "tree", without needing access to the root. 2 Main part: Make a separate public class called Main and put it into its own file. Put your entry point inside this class. Make sure to put Vis.class and Color.class in the same folder as your .java files if you plan on running your code on the command line (more on this below). Create an object of your BST class (call it whatever you like). You can now call whichever operations you want on your object. This will initialize your tree by giving it a set of nodes it will contain. When you are ready to see the visualize of your tree and test it in real-time, call Vis, test (nameofYourTreeobject); Here is an example (this code would appear inside your main function in your Main class): /I instantiate our BST object BST tree = new BST (); // load it up with some initial values tree.insert(5); tree.insert (15); tree.insert (2); 1/ are you on Windows? Vis. runonWindows = false; // set to true if running on Windows 1/ test it out Vis.test(tree); The test function will take your BST object and show it on the screen (in beautiful ASCII art fashion). It will also display a menu wherein you can test out any operation you want. All the operations you must implement are able to be tested here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
