Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update time complexity in update.rst #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant