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?

low = 0, high = 1
A

low = 0, high = 2
B

low = 1, high = 1
C

low = 2, high = 1
D

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

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 12:00, muncyemily
From excel to powerpoint, you can copy and paste a. cell ranges and charts, one at a time. b. cell ranges and charts, simultaneously. c. charts only. d. cell ranges only.
Answers: 3
image
Computers and Technology, 23.06.2019 16:00, keyonaemanieevans
Helen is having a meeting with her colleagues in her company. they are working on the goals and objectives for the coming year. they want to ensure that these goals and objectives of the processes involved are properly evaluated. which system can helen and her colleagues apply to evaluate this? helen and her colleagues require a blank to evaluate the goals and objectives.
Answers: 2
image
Computers and Technology, 23.06.2019 18:30, milkshakegrande101
Where can page numbers appear? check all that apply. in the header inside tables in the footer at the bottom of columns at the top of columns
Answers: 1
image
Computers and Technology, 24.06.2019 09:10, daedae11142
  to change the number of rows and columns displayed by the excel object a. select the object and drag a size handle on the active object. b. deselect the object and drag a size handle of the object. c. deselect the object and drag a row or column divider of the object. d. select the object and drag a row or column divider on the active object.
Answers: 2
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...

Questions in other subjects:

Konu
History, 18.11.2020 21:30
Konu
Social Studies, 18.11.2020 21:30
Konu
Mathematics, 18.11.2020 21:30