std::lower_bound and std::upper_bound STL functions in C++
Introduction: For a sorted sequence std::lower_bound and std::upper_bound are two very powerful functions in C++ STL, which can save you from writing a long code of binary search(specially in competitive programming). Basically these functions are used to find the lower bound or upper bound for a given value in a sorted sequence of elements (vector, arrays, sets, maps etc.) Definition: lower_bound for a value 'val' finds the location of the first element which is just greater than or equal to val . And upper_bound function for a value 'val' unlike lower_bound just finds the location of the first element which is just greater than val. Syntaxes: std::lower_bound ( iterator start, iterator last, const val ) ; std::upper_bound ( iterator start, iterator last, const val ) ; Time Complexity: In case of vectors, arrays it is O(log(n)) In case of sets, maps it is O(n) To get results in O(logn) in case of sets and maps we should use map.lower_bound(const val) inste...