There are constant number of buckets in the hashmap (let's say b)
We have N elements and assume N is very large and N >> b
Now each bucket contains N/b elements, assuming our hash function is good.
If we store elements in bucket as linked list, then searching in list of N/b elements is still O(N). Even if we assume that the elements in each bucket are stored as a tree, still searching in a tree of N/b elements is O(logN).
I know that b doubles every time the load factor reaches a threshold. Does this make b itself O(N). If that's the case then O(1) is explained. But if b is anything other than O(N) then how do we explain O(1) operations on map?
The word amortized
is used to describe the O(1), which I assume means average case rather than worst case. But even in the average case, I don't see how it's O(1).