简体   繁体   中英

Why is the time complexity for insertion of a string into an unordered_map, constant on average?

If we have a string of length n, then shouldn't the time for inserting it into an unordered_map (C++) be O(n)? But in the cplusplus.com website:

The following is written: 在此处输入图像描述

So, what is the correct time complexity? Thank you!

In this context, constant time refers to the number of elements in the map, not anything about those elements.

If you have a string of size n , and insert it into a map of size m , O(n) insertion is constant in m .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM