What is the complexity of the std::lower_bound
and std::upper_bound
functions.
I know in case of std::set<int>
it is log(n)
, but I have no idea for a std::vector<int>
.
I was going through an implementation of the Longest Increasing Subsequence using vectors and std::lower_bound
.
What is the complexity of this code?
int LIS2(vector<int> a) {
vector<int> v;
for (int i = 0; i < a.size(); i++) {
auto it = lower_bound(v.begin(), v.end(), a[i]);
if (it != v.end())
*it = a[i];
else
v.push_back(a[i]);
}
return v.size();
}