Binary Search uses Divide and Conquer algorithm to search given element in a sorted array.

Procedure:

- Divide array into half
- Compare given value with middle element, if matches return index
- If the value is greater then the middle element then values is in the left array then repeat the process with the left array.
- If the value is less than the middle element then the value is in the right array then repeat the process with the right array.

Time complexity for binary search is O(logn).

Example : https://github.com/santhoshgudla/DSTraining

Advertisements