What is the time complexity of std::map

后端 未结 4 1928
野趣味
野趣味 2020-12-19 03:00

What is the time complexity of std::map? And will it degenerate in the worst case? Or it is decide by the implementation, we can\'t know it?

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 03:05

    This depends on the implementation, you can't associate a complexity of any kind to std::map just by looking at the language specs.

    Usually an std::map is implemented as a Red-Black Tree and you can find all info about the Big-O properties of this kind of containers here.

    Notably there are less popular alternatives to the standard libraries shipped with popular compilers such as msvc or gcc, that implements this kind of containers with B-trees, this leads to lower memory usage due to the fact that a B-tree usually occupy less memory that an RB-tree.

    For example click here.

提交回复
热议问题