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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:30
What are listed in the vertical columns across the top of the event editor? a. file names b. conditions c. check marks d. action types
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
Answers: 2
question
Computers and Technology, 23.06.2019 21:40
Draw the resistor’s voltage and current phasors at t=15ms. draw the vectors with their tails at the origin. the orientation of your vectors will be graded. the exact length of your vectors will not be graded.
Answers: 2
question
Computers and Technology, 24.06.2019 06:00
Hey i really need some solving this problem: 1. encrypt this binary string into cipher text: 110000. include in your answer the formula the decoder would use to decrypt your cipher text in the format (coded answer) x n mod (m) = y & 2. decrypt this cipher text into a binary string: 106 you.
Answers: 2
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
question
Mathematics, 04.09.2019 08:10
question
Mathematics, 04.09.2019 08:10
question
English, 04.09.2019 08:10
Questions on the website: 13722363