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:
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.