Notes

Search

Search IconIcon to open search

Hash Performance

Last updated Dec 30, 2022

Unfortunately, the hash table we devised is $O(Q)$ for its operations, and $Q$ has $O(N)$ order of growth.

This is really bad, because eventually our operations will get slow.

We can fix this by adding more buckets!

Model

Suppose we have:

An example strategy: When $\frac{N}{M}$ is $\geq$ 1.5, then double M.

As long as $M = \Theta(N)$, then $N = \Theta(\frac{N}{M}) = O(1)$.

One thing to note is that when we do our resizing, items in our table will shuffle around and the lists will get shorter.

More specifically, with resizing, contains ia $\Theta(1)^{†}$ and add is $\Theta(1)^{* †}$. means that we assume items are evenly spread, and * means “on average”.