Recursive Binary Search Trace
Consider the following recursive binarySearch method.
public static int binarySearch(int[] arr, int target, int left, int right) {
if (left > right) {
return -1;
}
int mid = left + (right - left) / 2;
if (arr[mid] == target) {
return mid;
}
if (target < arr[mid]) {
return binarySearch(arr, target, left, mid - 1);
} else {
return binarySearch(arr, target, mid + 1, right);
}
}
What value is returned as a result of the call binarySearch(new int[]{2, 5, 8, 12, 16, 23, 38, 45, 67, 78}, 23, 0, 9)?
A
5
B
23
C
6
D
-1
Question Leaderboard
Not enough data yet to show leaderboard.
