Skip to content

Conversation

dg1223
Copy link

@dg1223 dg1223 commented Dec 7, 2023

The time complexity of dictionary update is linear, i.e. $O(N)$. The C implementation of Python dictionary does resizing, hasing and deleting in an amortized $O(1)$ time. So, the update method, which uses the C implementation of the dict_merge() function as source, uses a for loop to update the dictionary.

Sources:
https://hg.python.org/cpython/file/tip/Objects/dictobject.c
https://archive.org/details/pyvideo_276___the-mighty-dictionary-55
https://stackoverflow.com/questions/20906435/does-dictionary-do-resize-when-we-delete-an-item
https://stackoverflow.com/questions/52504598/time-complexity-of-python-dictionary-get-update-always-o1

The time complexity of dictionary update is linear, i.e. O(N). The C implementation of Python dictionary does resizing, hasing and deleting in an amortized O(1) time. So, the update method, which uses the C implementation of the dict_merge() function as source, uses a for loop to update the dictionary.

Sources:
https://hg.python.org/cpython/file/tip/Objects/dictobject.c
https://archive.org/details/pyvideo_276___the-mighty-dictionary-55
https://stackoverflow.com/questions/20906435/does-dictionary-do-resize-when-we-delete-an-item
https://stackoverflow.com/questions/52504598/time-complexity-of-python-dictionary-get-update-always-o1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant