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, 23.06.2019 06:30
You are consulting for a beverage distributor who is interested in determining the benefits it could achieve from implementing new information systems. what will you advise as the first step?
Answers: 1
question
Computers and Technology, 23.06.2019 07:00
You need a quick answer from a coworker. the most effective way to reach your coworker is through a. cloud server b. instant message c. teleconference d. telepresence
Answers: 1
question
Computers and Technology, 23.06.2019 10:00
What is estimated time of arrival (eta)? a device that measures the acceleration (the rate of change of velocity) of an item and is used to track truck speeds or taxi cab speeds a gps technology adventure game that posts the longitude and latitude location for an item on the internet for users to find a north/south measurement of position the time of day of an expected arrival at a certain destination and is typically used for navigation applications
Answers: 3
question
Computers and Technology, 24.06.2019 06:30
Ineed to know the anwser to all these questions
Answers: 2
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...
Questions
question
Mathematics, 13.11.2019 11:31
Questions on the website: 13722361