Computers and Technology, 09.04.2021 20:40 fmas6855
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
Answers: 1
Computers and Technology, 22.06.2019 23:00
In which part of a professional email should you try to be brief, but highly descriptive?
Answers: 1
Computers and Technology, 23.06.2019 19:30
You can apply several different worksheet themes from which tab?
Answers: 1
Computers and Technology, 23.06.2019 21:20
In microsoft word, when you highlight existing text you want to replace, you're in a. advanced mode. b. automatic mode. c. basic mode. d. typeover mode
Answers: 1
Consider the following method, which implements a recursive binary search.
/** Returns an index in...
Mathematics, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01
Biology, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01
History, 14.07.2020 01:01
English, 14.07.2020 01:01
History, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01
Mathematics, 14.07.2020 01:01