Java Programming Exercise 2 Another co-worker emails you and said she developed a recursive version for doing search in a binary search tree. Here’s the code for the function: public boolean...


Java Programming


Exercise 2


Another co-worker emails you and said she developed a recursive version for doing search in a binary search tree. Here’s the code for the function:


public boolean searchRecursive(Node current, int searchValue)


{


      if (current.data == searchValue)


            return true;


      else if (current == null)


            return false;


      else if (current.data > searchValue)


            return searchRecursive(current.left, searchValue);


      else


            return searchRecursive(current.right, searchValue);


}



She says that she “keeps getting an error” but unfortunately did not say if it was a compile error or a run-time error (or both). You analyze the code and see there is indeed an error and so you reply with the following:




  • Draw a picture of what a binary search tree would look like after inserting values of 5, 10, 8, 15, 4, 2, and 3 in that order

  • Next, tell her why she gets either a compile time error or run-time error (or both) and what happens when you do search(8) and then when you search(20)

  • Finally, tell her the code change(s) you would make to this code to get it to work properly



Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here