Solution Review: Recursive Binary Search
Have a look at the solution to the 'Recursive Binary Search' challenge.
We'll cover the following...
Rubric criteria
Solution
Press + to interact
class BinarySearch{public static int search(int[] array, int left, int right, int value){if(right >= left){int middle = (left + right)/2;if (array[middle] == value) // second base casereturn middle;else if(array[middle] > value) // first recursive casereturn search(array, left, middle-1, value);else // second recursive casereturn search(array, middle+1, right, value);}else // first base casereturn -1;}public static int binarySearch(int[]array, int value){return search(array, 0, array.length-1, value); // calling recursive method}public static void main(String args[]){int[] array = {1, 2, 3, 4, 5, 6};System.out.println( binarySearch(array, 5) );}}
Rubric-wise explanation
According to the problem statement, a call from the ...