(JAVA JAVA JAVA) Create a binary search tree but with an array implementation. T
ID: 3678547 • Letter: #
Question
(JAVA JAVA JAVA)
Create a binary search tree but with an array implementation. The data contained in this tree is positive integers, so it may help to initialize the entire tree as some negative sentinel value (like -1)s to indicate that certain values have not been populated. Download the driver file : https://cse.sc.edu/~shephejj/csce146/Labs/Lab08Driver/IntBSTreeTester.java
, in order to test it out.
The class IntBSTree is given fill in the following methods
insert: This method returns nothing and takes in an integer value that is then placed as a new node in the tree based on the binary tree properties. A reminder values greater than the parent go to the right subtree and values smaller go to the left subtree. Also it may be a good idea to use a recursive method in order to place these values.
printInorder: This method which returns nothing and has no parameters prints the in order traversal of the tree. For in order traversal each left subtree must be visited, then the value is printed out, and finally each of the right subtrees is visited. It is a good idea to make a recursive method to assist with this. Also if done correctly in-order traversals print out each of the integers in ascending order.
printBreadthOrder: This method which returns nothing and has no parameters prints the breadth order traversal of the tree. For this one each element in a row (in other words it and all of its siblings) are printed from left to right.
getDepth: The depth of a node is the number of edges from the root to that number. This method returns the depth and takes in a parameter corresponding to the integer value of a node whose depth is returned. If the value is not in the tree a -1 should be returned. Again a recursive helper method may be useful to solve this.
Correct Print Out:
Int BST Tester!
Creating tree
Populating Tree with values
Testing insertion by in-order traversal
1
2
3
4
5
6
7
8
9
10
Testing breadth order traversal
4
2
8
1
3
7
10
5
9
6
Getting depth of 6
4
Getting depth of 14
-1
——————————
Driver file :