public class HelloWorld { public static void main (String [] the argv) { int [] = ARR new new int [] {1,3,6,9,13,16,21,26,30,35 }; int NUM = 30 ; // to find the value of int Low = 0; // leftmost index values int High-= arr.length. 1; // standard value rightmost int MID = (High + Low) / 2 ; the while ( ARR [MID]! && NUM = Low! = High ) { // ARR [MID] <NUM looking for the representative value to the right in the middle IF (ARR [MID] < NUM) { low=mid+1; } // ARR [MID]> NUM looking for the representative value of the left intermediate the else IF (ARR [MID] < NUM) { high=mid-1; } MID = (High + Low) / 2; // re-calculates an intermediate value } IF (== Low High) { System.out.println ( "no value" ); } else { System.out.println ( "subscript is:" + MID); } }//endmain }//endclass
Red is the key dichotomy needs to be ordered array