Recursive Search Practice Quiz
Practice Problem
Take out a piece of paper and put your name on the upper right corner.
Write a recursive method to search a sorted array:
/**
* @return the index of value in the sorted array data, or -1 if value is not in the array.
*/
public static int binarySearch(int[] data, int value) { // the data array is sorted.
// your code here.
// you can use a recursive helper method
}
The binary search algorithm decides which half of the array the value is in by comparing the value to the middle of the array then searching the correct half.
Be sure to write JavaDoc comments for your code.
Conduct a quick review of your code, before you are done.
After the code, write an explanation the Big-O performance of the binarySearch method.
Time Remaining:
You can restart the timer by reloading the page.
Try to complete the problem in 15 minutes.
If you cannot complete the program in 15 minutes, you can watch me solve the problem in a text editor.