Perfection [in design] is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
Binary search is a method to find the particular item in the sorted array. In each step, the algorithm divides the array equally and match the middle item. If the key match with the middle item, the search returns the index. If the key is less than the middle element, search left subarray. Else search in the right subarray.
Binary search uses divide and conquers strategy to search the item from the sorted array. The binary search eliminates half of the elements for each iteration. It requires sorted array and will not work for the un-sorted array like linear search.
The binary search algorithm can be implemented using an iterative method and recursive method.
Before Sort: [12, 55, 45, 11, 23, 20, 17, 24, 9] After Sort: [9, 11, 12, 17, 20, 23, 24, 45, 55] Found in 2 Position!