subject

Consider the following method, which implements a recursive binary search. /** Returns an index in arr where target appears, if target appears

* in arr between arr[low] and arr[high], inclusive;

* otherwise, returns -1.

* Precondition: arr is sorted in ascending order.

* low >= 0, high < arr. length, arr. length > 0

*/

public static int binarySearch(int[] arr, int low, int high, int target)

{

if (low > high)

{

return -1;

}

int middle = (low + high) / 2;

if (target == arr[middle])

{

return middle;

}

else if (target < arr[middle])

{

return binarySearch(arr, low, middle - 1, target);

}

else

{

return binarySearch(arr, middle + 1, high, target);

}

}

The following code segment appears in a method in the same class as binarySearch.

int[] arr = {2, 3, 12, 34, 54};

int result = binarySearch(arr, 0, arr. length - 1, 5);

If the first call to binarySearch is the call in the code segment above, with low = 0 and high = 4, which, if any, of the following shows the values of low and high when binarySearch is called for the third time?

A. low = 0, high = 1

B. low = 0, high = 2

C. low = 1, high = 1

D. low = 2, high = 1

E. The method returns to the calling code segment before the third call to binarySearch.

ansver
Answers: 1

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 10:30
If calculating interest by the previous balance method, purchases and payments during the month __ counted in calculation of interest. a. are b. are not c. must be d. are sometimes
Answers: 1
question
Advanced Placement (AP), 23.06.2019 19:40
Want free points and brainliest? answer this drivers ed question correctly and you shall receive : ) in which of the following situations is it legal to pass? a. the vehicle you want to pass is driving at or above the speed limit in front of you. b. you must cross a center line that's solid on your side and broken on the opposite side. c. you are in the middle of crossing a bridge that only has one lane each direction. d. you are on a straight road and can pass the car ahead under the speed limit.
Answers: 2
question
Advanced Placement (AP), 23.06.2019 22:30
Nd to pa my drivers ed ill give you brainliest if answered a is marked by two sets of double yellow lines, with each set having a broken line on the inside, and a solid line on the outside. a. merge lane b. high-occupancy vehicle (hov) lane c. center left turn lane d. center right turn lane
Answers: 2
question
Advanced Placement (AP), 25.06.2019 11:30
To what extent was the chinese exclusion act a turning point in american foreign policy
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
Questions on the website: 13722359