C++ STL map: is access time O(1)?

后端 未结 3 463
臣服心动
臣服心动 2020-12-29 19:03

Is key look up on std::map O(1)? I thought it was until I thought about it more. It is based on a tree implementation so the lookup time should be O(log N), cor

3条回答
  •  无人及你
    2020-12-29 19:54

    Basicaly std::map is implimented using red-black tree. In red-black tree insert ans delete operation take O(LogN) time, so in std::map time complexity is O(LogN) of every element.

    std::unodered_map is implememted using hashing ,where every operation take O(1) time.

提交回复
热议问题