subject

The Binary Search algorithm works by testing a mid-point, then eliminating half of the list. In this exercise, you are going to take our binary search algorithm and add print statements so that you can track how the search executes. Inside of the recursive binary search function, add print statements to print out the starting, ending, and midpoint values each time. Then as you test a value, print out the results, either too high, too low, or a match. Sample OutputStarting value: 0Ending value: 9Testing midpoint value: 4Too high!Starting value: 0Ending value: 3Testing midpoint value: 1Too low!Starting value: 2Ending value: 3Testing midpoint value: 2Match!public class BinaryExplorer {public static void main(String[] args) {int[] testArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};binaryRec(testArray, 8, 0, testArray. length - 1);}/*** Add Print statements to the binaryRec method:** Print Starting, ending, and midpoint values.** Print when you find a match** Print if you are too high or too low.***/public static int binaryRec(int[] array, int target, int begin, int end) {if (begin <= end){ int mid = (begin + end) / 2; // Base Case if (target == array[mid]) { return mid; } if (target < array[mid]) {return binaryRec(array, target, begin, mid - 1);} if (target > array[mid]) { return binaryRec(array, target, mid + 1, end);}} return -1; //Alternate Base Case - not found}}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 00:30
Which of the following methods could be considered a “best practice” in terms of informing respondents how their answers to an on-line survey about personal information will be protected? respondents are informed that investigators will try to keep their participation confidential; however, confidentiality cannot be assured. respondents are informed that a research assistant will transfer all the research data to a password-protected computer that is not connected to the internet, via a usb flashdrive. the computer is located in a research team member’s office. the investigator uses the informed consent process to explain her institution’s method for guaranteeing absolute confidentiality of research data. the investigator uses the informed consent process to explain how respondent data will be transmitted from the website to his encrypted database without ever recording respondents’ ip addresses, but explains that on the internet confidentiality cannot be absolutely guaranteed.
Answers: 1
question
Computers and Technology, 22.06.2019 09:40
In the lab, which of the following displayed a list of all installed services and included a description of the service, the current state, and whether the service started automatically or manually? a. the services manager b. the applications summary c. the recommended services d. list the safe services list
Answers: 2
question
Computers and Technology, 22.06.2019 14:30
Complete the sentence based on your knowledge of the professional difficulties faced by music artists. digital technology allows audiences to see free live telecasts of music or dance performances through
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
What is the term for water wave that is created by an underwater earthquake
Answers: 1
You know the right answer?
The Binary Search algorithm works by testing a mid-point, then eliminating half of the list. In this...
Questions
question
Social Studies, 24.01.2020 07:31
question
History, 24.01.2020 07:31
question
English, 24.01.2020 07:31
question
Mathematics, 24.01.2020 07:31
Questions on the website: 13722363