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: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:50, Emptypockets451
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form. you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used. hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
image
Computers and Technology, 23.06.2019 00:30, Thisisdifinite
Which of the following would you find on a network
Answers: 3
image
Computers and Technology, 23.06.2019 16:30, 19thomasar
How to do this programming flowchart?
Answers: 3
image
Computers and Technology, 23.06.2019 18:00, sophx
Apunishment or the threat of punishment used to enforce conformity. select the best answer from the choices provided t f
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 in other subjects:

Konu
Mathematics, 13.07.2020 19:01
Konu
Mathematics, 13.07.2020 19:01