Skip to content Skip to sidebar Skip to footer

Is Dictionary In Python Can Be Seen As Map In C++

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 poi

Solution 1:

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

Solution 2:

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

Post a Comment for "Is Dictionary In Python Can Be Seen As Map In C++"