Binary search in sorted vector of pairs

How to apply STL binary_search to vector of pairs(key, value), given that vector is sorted by its first value(key)

struct compare in the code contains two function which compares the key(searching element) with the first element in the vector


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)

My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :
    Practice Tags :

    Be the First to upvote.

    Please write to us at to report any issue with the above content.