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!
My Personal Notes arrow_drop_up
- Recursive program to linearly search an element in a given array
- Meta Binary Search | One-Sided Binary Search
- Recursive function to do substring search
- Why is Binary Search preferred over Ternary Search?
- C Program for Anagram Substring Search (Or Search for all permutations)
- Linear Search vs Binary Search
- Interpolation search vs Binary search
- C Program for Recursive Insertion Sort
- C Program for Iterative Quick Sort
- C Program for Iterative Merge Sort
- Binary Search in PHP
- Binary Search
- The Ubiquitous Binary Search | Set 1
- Variants of Binary Search
- Binary Search a String