subject

Consider the following method, which implements a recursive binary search. /** Returns an index in arr where the value x appears if x appears

* in arr between arr[left] and arr[right], inclusive;

* otherwise returns -1.

* Precondition: arr is sorted in ascending order.

* left >= 0, right < arr. length, arr. length > 0

*/

public static int bSearch(int[] arr, int left, int right, int x)

{

if (right >= left)

{

int mid = (left + right) / 2;

if (arr[mid] == x)

{

return mid;

}

else if (arr[mid] > x)

{

return bSearch(arr, left, mid - 1, x);

}

else

{

return bSearch(arr, mid + 1, right, x);

}

}

return -1;

}

The following code segment appears in a method in the same class as bSearch.

int[] nums = {10, 20, 30, 40, 50};

int result = bSearch(nums, 0, nums. length - 1, 40);

How many times will the bSearch method be called as a result of executing the code segment, including the initial call?

1

1
A

2

2
B

3

3
C

4

4
D

5

5
E

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:50
Click on this link toopens a new window. bring up a flowchart in a new browser window. based on this flowchart, would a d-link 3347 gateway with an xbox 360 multiplayer problem be in scope or out of scope
Answers: 2
question
Computers and Technology, 22.06.2019 09:00
What is one way in which tablets differ from laptops and notebooks? tablets are designed for touch-based interaction. tablets are designed to be used as desktops. tablets are designed for input via a keyboard and mouse. tablets are designed to be larger than laptops.
Answers: 1
question
Computers and Technology, 24.06.2019 03:30
What is the purpose of a computer network needs assessment? to analyze which workers need more training to improve their performance to compare worker productivity to determine what steps employees can take to increase company revenue to evaluate how to move from the current status to the desired goal
Answers: 2
question
Computers and Technology, 24.06.2019 08:00
Can someone work out the answer as it comes up in one of my computer science exams and i don't understand the cryptovariables
Answers: 1
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
Questions on the website: 13722363