struct compare in the code contains two function which compares the key(searching element) with the first element in the vector
KEY ELEMENT 1 20 2 80 3 29 3 42 4 36 7 50 9 20 search for key 3 in vector Element found
The above binary_search operation has time complexity O(lg n)
- Meta Binary Search | One-Sided Binary Search
- Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
- Sorting Vector of Pairs in C++ | Set 2 (Sort in descending order by first and second)
- Convert an array to reduced form | Set 2 (Using vector of pairs)
- Why is Binary Search preferred over Ternary Search?
- Interpolation search vs Binary search
- Linear Search vs Binary Search
- Search in an almost sorted array
- Count pairs from two sorted matrices with given sum
- Search, insert and delete in a sorted array
- Search an element in a sorted and rotated array
- Search element in a Spirally sorted Matrix
- Count pairs from two sorted arrays whose sum is equal to a given value x
- Search in a sorted 2D matrix (Stored in row major order)
- Search equal, bigger or smaller in a sorted array in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.