Binary Search - Algorithm
Binary search is a fastest search algorithm with o(log n) time complexity.this algorithm is based on divide and conquer.the searching technique required collection in sorted meaner. this is biggest disadvantage of binary search. suppose we need to search on array then first we need to sort array and the perform search operation on that array. the solution in this case is first sort array and the use Binary search on the array. Algorithm : Step 1: initialize low = 0, high = size of collection step 2 : while low <= high then calculate the mid i.e mid = low + high/2 step 3 : if(searchValue == array[mid]){print Element found} step 4 : if(searchValue > array[mid]){low = mid + 1} otherwise high = mid -1 step 5 : Exit Programmatic Representation : while(low <= high){ mid = low+high/2; if(x== a[mid]){ Print : Element Found. break; } ...