Is dictionary in Python can be seen as Map in C++
And the insert complexity is constant time? and what about sort complexity of dictionary? What about iteration?
Need some good points or link to good resource.
Thanks!
If I recall correctly, the C++ map implementation uses a tree, so insertion and retrieval is O(log(n)) as opposed to O(1).
Python uses hashtables, so retrieval is O(1).
Python dicts are an implementation of the generic data structure commonly referred to as a hash table or hash map.
For Python dicts, complexities are what you would expect from an efficient implementation of a hash table; insert is constant time; iteration is O(N). Dictionaries are unsorted; if you want something that's sorted you generally transform it into something else (like a list).
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.