I have always assumed that std::lower_bound()
runs in logarithmic time if I pass a pair of red-black tree iterators (set::iterator
or map::it
There are multiple reasons:
std::map
as the map predicate operates on K
s while the range operates on pairs of K
and V
.t.begin()
and the t.end()
of the tree. They can be somewhere in the tree, making the use of the tree structure potentially inefficient.The part I consider questionable is the use of a generic name for an algorithm which has linear complexity with bidirectional iterators and logarithmic complexity with random access iterators (I understand that the number of comparisons has logarithmic complexity in both cases and that the movements are considered to be fast).