[18885 views]
Binary Search is one of the Fastest Searching Algorithm with run-time complexity of Ο(log n). Binary Search Algorithm works on Divide and Conquer principle. The only condition for this algorithm is that the Data Collection should be in sorted form. i.e All the Elements in an Array should be sorted.
Binary search searches for a particular item by first comparing the middle most element of the collection. If a match occurs, then the index value of the element is returned. If the middle item is greater than the element, then the element is searched in the sub-array to the left of the middle element. Otherwise, the element is searched in the sub-array to the right of the middle element. This procedure continues on the sub-array as well until the size of the subarray reduces to zero.
The above Binary Search Algorithm first sorts the array and then searches for the item in the array.