struct compare in the code contains two functions 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)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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?
- Implementation of lower_bound() and upper_bound() in Vector of Pairs in C++
- 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)
- Search in an almost sorted array
- Linear Search vs Binary Search
- Interpolation search vs Binary search
- Search element in a Spirally sorted Matrix
- Search an element in a sorted and rotated array
- Search, insert and delete in a sorted array
- Search in a sorted 2D matrix (Stored in row major order)
- Count pairs from two sorted matrices with given sum
- Search equal, bigger or smaller in a sorted array in Java
- Count pairs from two sorted arrays whose sum is equal to a given value x
- Binary Search
- Binary Search using pthread
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.
Improved By : Code_Mech