subject

Consider the following method, which implements a recursive binary search. /** Returns an index in theList where target appears,
* if target appears in theList between the elements at indices
* low and high, inclusive; otherwise returns -1.
* Precondition: theList is sorted in ascending order.
* low >= 0, high < theList. size(), theList. size() > 0
*/
public static int binarySearch(ArrayList theList, int low, int high,
int target)
{
if (low > high)
{
return -1;
}
int middle = (low + high) / 2;
if (target == theList. get(middle))
{
return middle;
}
else if (target < theList. get(middle))
{
return binarySearch(theList, low, middle - 1, target);
}
else
{
return binarySearch(theList, middle + 1, high, target);
}
}
The following code segment appears in a method in the same class as binarySearch.

ArrayList theList = new ArrayList ();
for (int k = 10; k < 65; k = k + 5)
{
theList. add(k);
}
int result = binarySearch(theList, 0, theList. size() - 1, 45);
Including the call to binarySearch in the last statement of the given code segment, how many times will binarySearch be called before a value is returned?

1- A

2- B

3- C

4- D

8- E

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, suyi14
What operating system is a smartphone most likely to use? 1.bsd 2.mac os x 3.symbian 4.linux
Answers: 1
image
Computers and Technology, 23.06.2019 17:30, Annlee23
When making changes to optimize part of a processor, it is often the case that speeding up one type of instruction comes at the cost of slowing down something else. for example, if we put in a complicated fast floating-point unit, that takes space, and something might have to be moved farther away from the middle to accommodate it, adding an extra cycle in delay to reach that unit. the basic amdahl's law equation does not take into account this trade-off. a. if the new fast floating-point unit speeds up floating-point operations by, on average, 2ă—, and floating-point operations take 20% of the original program's execution time, what is the overall speedup (ignoring the penalty to any other instructions)? b. now assume that speeding up the floating-point unit slowed down data cache accesses, resulting in a 1.5ă— slowdown (or 2/3 speedup). data cache accesses consume 10% of the execution time. what is the overall speedup now? c. after implementing the new floating-point operations, what percentage of execution time is spent on floating-point operations? what percentage is spent on data cache accesses?
Answers: 2
image
Computers and Technology, 24.06.2019 03:30, ilovewaffles70
Auniform resource locator (url) is a formatted string of text that web browsers, email applications, and other software programs use to identify a particular resource on the internet. true false
Answers: 2
image
Computers and Technology, 25.06.2019 01:00, jimmymurray29
When a new name is registered on the internet, the process can take two hours to four hours four hours to three days two hours to two days one hour to eight hours
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...

Questions in other subjects:

Konu
Mathematics, 09.06.2021 18:10