0

If python dictionaries are essentially hash tables and the length of hashes used in the python dictionary implementation is 32 bits, that would mean that regardless of the number of key-value pairs that actually exist in any given dictionary the size of the dictionary is static and fixed with a length of 232.

Such an implementation would be a waste of memory so I'm assuming this isn't the actual space complexity. How is a python dictionary actually implemented and what is its space complexity?

asked May 13, 2020 at 13:46

1 Answer 1

5

Space complexity is a property of algorithms, not of data-structures. And your assumption that the dictionary has a (large) fixed size would imply that it is O(1).

It doesn't start with the maximum size, but instead uses some fraction of the hash to index a smaller allocation. When it grows too large, it will re-hash the contents into a larger allocation.

answered May 13, 2020 at 13:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.