How a hash table grows
Keys land in buckets by hash. When the table gets crowded it doubles and re-hashes everything, which is what keeps lookups fast.
Tweak it
Break it
Normal run: the table doubles whenever items ÷ buckets passes the threshold.
What to notice
- Each key goes to bucket
hash(key) mod buckets. Two keys in one bucket is a collision, and they form a chain. - A resize is expensive (every key moves), but it happens rarely and halves the load factor. Total work stays roughly linear.
- Notice keys jump to different buckets after a resize, because the modulus changed. Same hash, new home.
- Turn on Break it: chains grow linearly, so inserts and lookups drift from O(1) toward O(n).