From the Python wiki on Time Complexity, following are the costs for performing operations on a dict.
Operation Average Case Amortized Worst Case
Copy[2] O(n) O(n)
Get Item O(1) O(n)
Set Item[1] O(1) O(n)
Delete Item O(1) O(n)
Iteration[2] O(n) O(n)
From my understanding of hash tables, the setting of a key, when the hashtable is full beyond the threshold value might result in resizing of the hash table, which means a worst case complexity of O(n)
is possible.
But in which case can Get
ting or Delete
ing an item have the Amortized Worst Case complexities of O(n)
?