multiset, map and hash map complexity

前端 未结 2 1554
一生所求
一生所求 2020-11-28 18:41

I would like to know the complexity in Big O notation of the STL multiset, map and hash map classes when:

  • inserting entries
  • accessing entries
2条回答
  •  甜味超标
    2020-11-28 19:25

    You can find this information in the SGI STL documentation: http://www.sgi.com/tech/stl/

    Basically, both multiset and maps are sorted binary trees, so inserting/finding 1 out of N entries takes O(log N). See Sorted Assoc. Containers in the documentation.

    Obviously, the big advantage of Hashmap is O(1) for inserting and finding entries.

    Accessing it after found is O(1) for all structures. Comparison, what do you mean by that? Sounds like O(1) to me, after all were found.

提交回复
热议问题