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

1
A

2

2
B

3

3
C

4

4
D

5

5
E

Submit

ansver
Answers: 3

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 22.06.2019 07:50
Aatividade em equipe consiste na sistematizaç? o crítica sobre empreendedorismo. dever? o serem retomadas as equipes feitas na semana anterior (de 3 a 4 estudantes). os estudantes dever? o retomar o negócio e as demais características que foram identificados na semana anterior (principais concorrentes do negócio, modismo ou uma tend? ncia e o risco em iniciar o negócio), para desenvolverem um plano para iniciar o negócio. desta forma, dever? o pensar em valores fictícios de máquinas e equipamentos, aluguel ou compra do local, propaganda, e estratégias para se manter no mercado.
Answers: 3
question
Advanced Placement (AP), 24.06.2019 22:00
How will not wearing a seatbelt affect you as a now and the in the future
Answers: 1
question
Advanced Placement (AP), 26.06.2019 04:00
Analyze the misfit’s statement: “she would have been a good it had been somebody there to shoot her everyday of her life.”
Answers: 1
question
Advanced Placement (AP), 27.06.2019 02:30
Christianity shares a hearth with which two religions? islam and judaism judaism and hinduism shintoism and taoism buddhism and hinduism islam and buddhism
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
question
English, 29.09.2019 19:00
Questions on the website: 13722362