Consider the following method, which implements a recursive binary search.

/** Returns an index in arr where target appears, if target appears

* in arr between arr[low] and arr[high], inclusive;

* otherwise, returns -1.

* Precondition: arr is sorted in ascending order.

* low >= 0, high < arr.length, arr.length > 0

*/

public static int binarySearch(int[] arr, int low, int high, int target)

{

if (low > high)

{

return -1;

}

int middle = (low + high) / 2;

if (target == arr[middle])

{

return middle;

}

else if (target < arr[middle])

{

return binarySearch(arr, low, middle - 1, target);

}

else

{

return binarySearch(arr, middle + 1, high, target);

}

}

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

int[] arr = {2, 3, 12, 34, 54};

int result = binarySearch(arr, 0, arr.length - 1, 5);

If the first call to binarySearch is the call in the code segment above, with low = 0 and high = 4, which, if any, of the following shows the values of low and high when binarySearch is called for the third time?

A. low = 0, high = 1

B. low = 0, high = 2

C. low = 1, high = 1

D. low = 2, high = 1

E. The method returns to the calling code segment before the third call to binarySearch.

Answers

Answer 1

Answer:

D. low = 2, high = 1

Explanation:

Middle is 2

First call: low = 0 high = 1

Middle is 0

Second call: low = 1 high = 1

Middle is 2

Third call: low = 2 high = 1

Answer 2

A technique of identifying a problem (or a set of strategies) in elements of (a simplified version of) itself is known as recursion. therefore, the final answer is "low = 1, high = 1".

Recursion:

In the given code, an integer array that is "arr" holds an integer value.In the next step, an integer variable "result" is declared that calls the binarySearch method.In the first time calls Recursion 1, when low = 0 and high = 4 its mid = 2, therefore arr[2] = 12 > 5 = high = mid-1In the second time calls Recursion 2, when low = 0 and high = 1 its mid =0, therefore arr[0] = 2 < 5 = low = mid+1In the third time calls Recursion 3, when low = 1 and high = 1 its mid =1, therefore arr[1] = 3 < 5 = element not found

Therefore, the final answer is "Option C", that is "low = 1, high = 1".

Find out more information about the Recursion here:

brainly.com/question/17298888


Related Questions

Cheryl made a one-time deposit at Eagle Savings & Loan of $6,400. The bank offers a 4.5% interest rate compounded annually. What is the amount of interest Cheryl will earn at the end of 5 years? A $7,975.56 B $34,622.30 C $1,440.00 D$1,575.56

Answers

Answer:  my teacher reviewed this problem so here you go sorry its late

Explanation:

1,575.56

A_____ is the place where an organism lives.

Answers

Answer:

Habitat.

Explanation:

A habitat, or a natural home that an organism presides in, is the place where an organism lives.

~

Answer:

H-A-B-I-T-A-T

Habitat

ASAP PLEASE ANSWER 100 POINTS
A person desires to run for the US House of Representatives.

(A) Describe the process the person must undertake to secure a party nomination.

(B) In the context of the scenario, explain how political action committees influence the process described in part A.

(C) Explain how the process described in part B will affect the behavior of a member of Congress.

Answers

Answer:

Explanation:

(A) To secure a party nomination, there is usually a vote by members of that party. If there are more than one candidate, then the person with the highest number of votes will get the party nomination.

(B) Political action committees are special interest groups with money. They use it to buy TV ads and other promotions for candidates. It makes candidates they support more likely to be nominated.

(C) When a candidate receives support from a PAC, it is more likely the candidate will listen to its opinions. When the candidate is elected to Congress, the PAC will gain influence for its special interest.

what are some ways to give back to the community

Answers

Answer: Donate. Sometimes giving back to the community is as simple as giving

Explanation:

You could provide meals for homeless, pick up trash, donate (as said above), shop at your local stores (you’d be giving back to the shops which all around brings money into the community, helping it)... there really are lots of ways to help, but these are just a few of em. Hope this helps.
Other Questions
find the value of x8(x6)=32 PLEASE HELP ME I WANT TO PASS THIS CLASS AND GRADUATE WILL GIVE BRAINLIESTA recent study of high school students shows the percentage of females and males who have at LEAST one notation in their school record for inappropriate behavior. A simple random sample of high school students was interviewed. The students were asked whether they had a notation for inappropriate behavior in their school record. Of the 100 females, 21 answered yes, as did 145 of the 400 males.Part A: Construct and interpret a 99% confidence interval for the difference in population proportions of females and males who have at LEAST one notation for inappropriate behavior. Be sure to state the parameter, check conditions, perform calculations, and make conclusion(s). (8 points)Part B: Does your interval from part A give convincing evidence of a difference between the population proportions? Explain. (2 points) ASAP!!! and no links please 25 points!!!!!The radius of a can of soda is 0.75 inches. Find the area of the top of the can. Round to the nearest hundredth.(Values only! No units!) What conflict did Naomi face and how did she cope with it? Why did she want Ruth and Orpah to go back to Moab? And how did she resolve her conflict? Choose the term that best matches the description given.The act that provides protection against hacking into your personal information that is stored in records or archives on servers:Pls help me I will give best answer, and if you have the other question answer that would help 100 POINTS!!!! What does Ensler suggest by her descriptions and explanation of the elusive nature of security? What does she mean by the term hard matter identity?What is the new paradigm she discusses? (A paradigm is a system, organization, or pattern of behavior, beliefs, or practices.) How are the examples of those people who are willing to compromise their security essential to creating a new way of thinking and a new form of security?How do those who risk their security open up a dialogue and discussion and promote a sense of inclusion in unlikely places?What, in Enslers opinion, are some of the consequences of the desire to feel secure?Ensler is actively working to raise social consciousness because of what she sees as the desecration (destruction) of the primary resource of the world. What messages or themes are you left with from Enslers work and activism?How do you think security influences your sense of self, identity, and understanding of the world around you? Does Enslers talk seem relevant to you? Why or why not? Need help1. 15% of what number is 6?2. 25 is 10% of what number3. 49 is 35% of what number4. What is 310% of 65Thanks Calpurnia requests Scout's presence in the kitchen and furiously reprimands Scout for her behavior. Calpurnia tells Scout that she needs to treat her company with respect, regardless of the person's social status. Calpurnia then smacks Scout and makes her eat in the kitchen for the remainder of the meal. Is this Correct from the Book Called To Kill a Mockingbird (HALP ILL GIVE BRAINLY AND IS A MULTIPLE CHOICE) no links or I will report As a bank loan officer, you are considering a loan application by Peak Performance Sporting Goods. The company has provided you with the following information: Cash $ 25,000 Accounts Receivable 45,000 Inventory 140,000 Fixed Assets 190,000 Current Liabilities 70,000 Long-term Liabilities 90,000 Peak Performance's debt to owners' equity ratio (rounded to the nearest tenth of a percent) is: Why is it important for developers to be careful when using cascading deletes?They may create orphaned records.They may link to data in external databases.They may delete more records than intended.They may disconnect the bond between tables. 6. Poison Ivy is also known as Rhus toxicodendron. Its species identifier is:Rhuspoisontoxicondendronivy PLEASE HELP! WILL GIVE BRAINLIEST! After substituting, what is the first step when evaluating 4y+9 when y=82 O Add 4 and 9. O Multiply 8 by 4. O Divide 9 by 7 O Divide 4 by 7. Which European River flows from East to West?A.Danube RiverB.Rhine RiverC.Tigris RiverD.Euphrates River 2x1+0x2+3x3=34x1-3x2+7x3=58x1-9x2+15x3=10solve the system using Gaussian or Gauss-Jordan elimination How does the amount of available energy change at each level as you move from level A to level D?A. The amount of available energy INCREASES by 100%B. The amount of available DECREASES by 90% every time you move up a stepC. The amount of available INCREASES by 10% every time you move up a stepD. The amount of available DECREASES by 50%(I THINK IT'S C BUT IM NOT SURE!!! HELP) Taylor had a bag of 28 marbles. 5 red, 9 blue, 8 yellow, and 6 black. If Taylor pulled out a yellow one and DID NOT put it back in. What is the probability of pulling out a blue marble (SIMPLIFY YOUR FRACTION). / Annual starting salaries for college graduates with degrees in business administration are generally expected to have a population standard deviation of $3,000. Assume that a 95% confidence interval estimate of the population mean annual starting salary is desired. How large a sample should be taken if the desired margin of error is (a) [1 pt] $500 someone please help I have no idea what to do A 12-pound bag weighs more than a 200-ounce bag. True or false