subject

Consider the following method, which implements a recursive binary search. /** Returns an index in nums where target appears if target
* appears in nums between nums[lo] and nums[hi], inclusive;
* otherwise, returns -1.
* Precondition: nums is sorted in ascending order.
* lo >= 0, hi < nums. length, nums. length > 0
*/
public static int bSearch(int[] nums, int lo, int hi, int target)
{
if (hi >= lo)
{
int mid = (lo + hi) / 2;
if (nums[mid] == target)
{
return mid;
}
if (nums[mid] > target)
{
return bSearch(nums, lo, mid - 1, target);
}
else
{
return bSearch(nums, mid + 1, hi, target);
}
}
return -1;
}
The following code segment appears in a method in the same class as bSearch.

int target = 3;
int[] nums = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
int targetIndex = bSearch(nums, 0, nums. length - 1, target);
How many times will bSearch be called as a result of executing the code segment above?

1- A

2- B

3- C

4-D

5-E

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 13:00
Which one of the following voltages should never be measured directly with a vom? a. 1200 v b. 500 v c. 800 v d. 100v
Answers: 2
question
Computers and Technology, 23.06.2019 21:30
To move a file or folder in microsoft windows, you can click and hold down the left mouse button while moving your mouse pointer to the location you want the file or folder to be, which is also known as.
Answers: 3
question
Computers and Technology, 24.06.2019 00:30
The best definition of an idiom is a. a word or phrase that describes a noun b. a word or phrase describing a verb c. a phrase containing figurative language in which the word expresses a different idea from its exact meaning d. a phrase that compares two unlike objects or ideas
Answers: 2
question
Computers and Technology, 24.06.2019 14:30
In a home that has 120 v service, there is an electric appliance that has a resistance of 12 ohms. how much power will this appliance consume? a. 10 w b. 120 w c 1200 w d. 1440 w
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions