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: 1. 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 2. 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) 3. Finally, tell her the code change(s) you would make to this code to get it to work properly
Java
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:
1. 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
2. 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)
3. Finally, tell her the code change(s) you would make to this code to get it to work properly
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images