c++ - 迭代 std::set/std::map 的时间复杂度是多少?

标签 c++ stl time-complexity big-o std

遍历 std::set/std::multiset/std::map/ 的时间复杂度是多少std::multimap?我相信它在集合/ map 的大小上是线性的,但不太确定。语言标准中有规定吗?

最佳答案

draft C++11 standard N3337答案可以在 § 24.2.1 第 8 段中找到:

All the categories of iterators require only those functions that are realizable for a given category in constant time (amortized).

由于对迭代器的每个操作都必须是常数时间,因此遍历 n 元素必须是 O(n)

关于c++ - 迭代 std::set/std::map 的时间复杂度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11779859/

相关文章:

c++ - 自动售货机c++

c++ - 为什么 std::map<int, float> 不能使用 operator[]: error C2678?

algorithm - 如何确定算法是否需要伪多项式时间?

c++ - openGL,C++,如何移动导入的 OBJ 对象?

C++ Qt - 以编程方式检查 Steam 游戏是否正在运行

javascript - 将纹理叠加到 STL 加载的网格上

c++ - 无法分配没有可行重载 '=' 错误的迭代器

algorithm - 计算转置矩阵的时间复杂度

big-o - 如何为我的循环找到 Big-O 符号?

c++ - 'sizeof' 对不完整类型 'QImage' 的无效应用