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 20:00
How is the number 372 written when expanded out to place values in the base 8 (octal) number system? a. 2 x 4 + 3 x 2 + 4 x 1 b. 3 x 64 + 7 x 8 + 2 x 1 c. 3 x 8 + 7 x 7 + 2 x 6 d. 3 x 100 + 7 x 10 + 2 x 1
Answers: 1
question
Computers and Technology, 23.06.2019 03:10
Acomputer has a two-level cache. suppose that 60% of the memory references hit on the first level cache, 35% hit on the second level, and 5% miss. the access times are 5 nsec, 15 nsec, and 60 nsec, respectively, where the times for the level 2 cache and memory start counting at the moment it is known that they are needed (e.g., a level 2 cache access does not even start until the level 1 cache miss occurs). what is the average access time?
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
Jenny wants to create an animated short video to add to her website. which software will she use to create this animated video?
Answers: 1
question
Computers and Technology, 24.06.2019 23:30
Game design colleges anyone know the requirements? ?
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
question
Mathematics, 18.03.2021 02:50
question
Mathematics, 18.03.2021 02:50
question
Mathematics, 18.03.2021 02:50
question
Physics, 18.03.2021 02:50
question
Social Studies, 18.03.2021 02:50
Questions on the website: 13722359