An unsorted array is searched through linear search that scans the array elements one by one until the wanted element is found.

The cause for sorting an array is that we search the array "quickly". Now, if the array is sorted, we can use binary search, which greatly halves the size of the search space each time it study one array element.

An array-based binary search chooses the middle element in the array & compares its value to that of the key value. Since, the array is sorted; if the key value is less than the middle value then the key has to be in the first half of the array. Similarly, if the value of the key item is greater than that of the middle value within the array, then it is known that the key lies into second half of the array. In either case, in reality we can, "throw out" one half of search space or array along with only one comparison.

Now, knowing that the key has to be in one half of the array or the other, the binary search study the mid value of the half wherein the key has to reside. Thus, the algorithm narrows the search area by half at each step till it has either found the key data or the search fails.

As the name recommend, binary means two, so it split an array into two halves for searching. This search is applicable only onto an ordered table (in either ascending or in descending order).

Let us write down an algorithm for Binary Search & then we will discuss it. The array contains elements stored in ascending order.