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 08:50
Can online classes such as gradpoint track your ip location like if im taking a final and i give somebody else my account and they take the final for me will it show where they are taking the final from? and can this be countered with a vpn
Answers: 1
question
Computers and Technology, 22.06.2019 10:30
Aconstruction company is creating a powerpoint presentation describing how they calculate costs during each construction step. they plan to email this presentation to clients. the individual clients will be watching the presentation slide show on their own personal computers. what is the most important formatting step the company should take to make the text readable and pleasing to the eye?
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
Im doing this last minute and literally none of my neighbors or people that my dad works with use excel so if anyone could me make up an example
Answers: 1
question
Computers and Technology, 22.06.2019 23:50
List a few alternative options and input and output over the standerd keyboard and monitor. explain their functioning in details.
Answers: 2
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
English, 11.03.2021 22:50
question
German, 11.03.2021 22:50
question
Arts, 11.03.2021 22:50
question
Mathematics, 11.03.2021 22:50
question
Physics, 11.03.2021 22:50
question
Mathematics, 11.03.2021 22:50
question
History, 11.03.2021 22:50
question
Mathematics, 11.03.2021 22:50
question
Mathematics, 11.03.2021 22:50
Questions on the website: 13722361