Binary search

Binary search is higher than the linear search. However, it cannot be tested on the unsorted data structure. The binary search is based on the method divide-and-conquer. The binary search begins by testing the data in the middle component of the array. This determines an object is whether in the first half or second half. If the object is in the first half, we do not need to check the second half and if it is in the second half no need to check in the first half. Similarly, we repeat this procedure until we find an object in the list or not found from the list. Here we need three variables to identify first, last and middle elements.

To implement a binary search technique, the item must be in sorted order.
Binary Search is performed as follows:
The key is compared with an element in the middle position of an array
If the key matches with an element, return it and stop.
If the key is less than mid-position element, then the element to be found must be in the first half of the array, otherwise, it must be in the second half of the array.
Repeat the method for the lower (or upper half) of the array until the component is found.
Posted on by