Question: Write a program to implement binary search. Partial program is given as below: class BinarySearch { private static int binarySearch (int arr [], int
Write a program to implement binary search. Partial program is given as below: class BinarySearch { private static int binarySearch (int arr [], int target) { } int low = 0; int high arr.length - 1; int i=0; int middleIndexNumber = arr [middleIndex]; /*Print out information. You should print out the order of the loop (e.g., "This is loop 1"), the index of the midpoint of each loop, and the number of the midpoint of each loop. */ while (low middle IndexNumber) { low = 3 return -1; public static void main(String args[]) { int [] NumerArray = (2,6,7,9,12, 18, 22, 25, 27, 29); System.out.println ("The index of the targeted number is " +binarySearch (NumerArray, 27)+" "); } If you run your code, the result should look like: BinarySearch [Java Application] C:\Program Files\Eclipse Foundation\t This is loop 1 The index of midPoint is 4 The number in the midPoint is 12 This is loop 2 The index of midPoint is 7 The number in the midPoint is 25 This is loop 3 The index of midPoint is 8. The number in the midPoint is 27 The index of the targeted number is 8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
