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
- Recursive function to do substring search
- Meta Binary Search | One-Sided Binary 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 Merge Sort
- C Program for Iterative Quick Sort
- Binary Search in PHP
- Binary Search
- Uniform Binary Search
- Variants of Binary Search