我知道有 std::set::lower_bound
,时间复杂度为O(log)
,同时我注意到在操作 std::set
时,std::lower_bound
比 std::set::lower_bound
慢得多。
我在谷歌上搜到了这个:
http://zh.cppreference.com/w/cpp/algorithm/lower_bound http://zh.cppreference.com/w/cpp/iterator/advance
所以很明显,因为std::advance
在set::iterator
上是线性的,整个std::lower_bound
最坏情况下的时间复杂度为O(n)
。
但是当我使用它时(我的一些朋友也是如此),它运行得比O(n)
快得多,有人能解释一下为什么吗,或者告诉我这不是真的。