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)
- Create a Sorted Array Using Binary Search
- Meta Binary Search | One-Sided Binary Search
- Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
- Convert an array to reduced form | Set 2 (Using vector of pairs)
- Sorting Vector of Pairs in C++ | Set 2 (Sort in descending order by first and second)
- Why is Binary Search preferred over Ternary Search?
- Linear Search vs Binary Search
- Interpolation search vs Binary search
- Search in an almost sorted array
- Search, insert and delete in a sorted array
- Search element in a Spirally sorted Matrix
- Search an element in a sorted and rotated array
- Count pairs from two sorted matrices with given sum
- Search in a sorted 2D matrix (Stored in row major order)
- Count pairs from two sorted arrays whose sum is equal to a given value x
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.