We basically ignore half of the elements just after one comparison.
- Compare x with the middle element.
- If x matches with middle element, we return the mid index.
- Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half.
- Else (x is smaller) recur for the left half.
Please refer complete article on Binary Search for more details!
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.