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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 14:30
Complete the sentence based on your knowledge of the professional difficulties faced by music artists. digital technology allows audiences to see free live telecasts of music or dance performances through
Answers: 1
question
Computers and Technology, 22.06.2019 21:30
The graph shows median weekly earnings for full-time workers according to education level. which can you not conclude?
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
What are some ways to use a range name in a formula? check all that apply. in the defined names group, click use in formula, and then select the desired name. begin typing the name in the formula, select a name from the autocomplete list, and use the arrow keys and tab key to enter the name in the formula. begin typing the formula, and then click and drag with the mouse to select the cells to include in the formula. right-click one of the cells in the range. click formula options, and use the dialog box to add the name.
Answers: 1
question
Computers and Technology, 23.06.2019 02:30
What is the power dissipated by a resistor with a current of 0.02 a and a resistance of 1,000 ? a. 200 w b. 20 w c. 0.4 w d. 4 w
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
question
Chemistry, 22.04.2020 21:40
question
Social Studies, 22.04.2020 21:40
question
English, 22.04.2020 21:40
question
Mathematics, 22.04.2020 21:40
Questions on the website: 13722367