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
- Check if an array is sorted and rotated using Binary Search
- Meta Binary Search | One-Sided Binary Search
- Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
- Why is Binary Search preferred over Ternary Search?
- 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)
- 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)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.