How Binary Search Works with Example
How Binary Search Works with Example Binary Search : To find an value in array we are having different ways and binary search is one of the most efficient way. It will reduce the no. of iteration to find the solution thus get us the solution quickly. In simple form, we need to do 3 checks as follows : target value = the value to find in the array. 1. if the target value = array[mid] => return the index. 2. if target value is smaller, than start searching on the left side else search on right side. 3. Keep repeating the process till either you get the value or till you iterate elements in array. How Binary Search Works : Learn by solving a Problem : Write a method to find an index of an element in an ascending Sorted Array using Binary Search. If element doesn't exist return -1. Illustration 1 : a[] = {1,2,4,5,7,8,10} , Find 5 ...