![]() |
VOOZH | about |
The std::set::lower_bound() method is used to find the first element in the set that is equal to or greater than the given value. It is a member function of std::set class and is defined inside <set> header file. In this article, we will learn about std::set::lower_bound() function in C++.
Example:
5
s.lower_bound(val);
The following examples demonstrate the behaviors of set::lower_bound() function in different cases.
geeks
Time Complexity: O(log n), where n is the number of elements in the set.
Auxiliary Space: O(1)
Lower Bound NOT Present.
Time Complexity: O(log n), where n is the number of elements in the set.
Auxiliary Space: O(1)
7 is present.
Time Complexity: O(log n), where n is the number of elements in the set.
Auxiliary Space: O(1)
The std::set::lower_bound() function uses the search operation of std::set container which is internally implemented as self-balancing binary search tree. So, for searching the lower bound of any value, we move from the root node of the tree using the path that may contain the lower bound.
That is why, the complexity of the set::lower_bound() function is same as the search operation of self-balancing binary search tree.