Objective : This seems strangely familiar. Create a binary search tree but with
ID: 3678209 • Letter: O
Question
Objective: This seems strangely familiar. 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, 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 nothing 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 Lab Report Questions: 1. Show how the array will look after each step when inserting the numbers {14, 17, 7, 20, 5, 11, 15} 2. Show how the array will look after the number 14 is removed from the previous tree.
Explanation / Answer
First I want to tell question is not very clear. what do you want to know how the array will look after adding the element to the existing array or its a fresh insertion? still I am providing the answer as far as I understand.
1. the array will look like : int[] valARrr = {4,2,8,1,3,7,10,5,9,14,6,11,17,15,20}
2. if the no.14 is removed then the place will be occupied by its inorder successor or predecessor. Acoording to that int[] valARrr = {4,2,8,1,3,7,10,5,9,11,6,17,15,20} replaced by successor
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.