Hash Table Resizing and Rehashing
After a capacity change, recompute where each key belongs under the new bucket count.
Core Intuition & How It Works
As a hash table’s load factor (items / buckets) rises, collision chains lengthen and lookups slow down. Resizing allocates a larger bucket array—usually 2×—and rehashes every existing key to restore O(1) expected operations.
In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.
Time & Space Complexity
| Metric | Complexity |
|---|---|
| Time Complexity | O(1) amortized insert, O(n) rehash |
| Space Complexity | O(n) |
| Topic Chapter | Chapter 6: Hashing |
| Difficulty Level | Intermediate |
Key Pattern to Recognize
Recompute key hashes modulo the new bucket count during resizing; never copy old buckets to the same indices blindly.
Common Pitfalls & Edge Cases
Choosing a load factor threshold too close to 1.0 in open addressing, causing severe primary clustering and probe spikes.
Real-World & Technical Interview Applications
Dynamic hash maps, distributed consistent hashing rings, and in-memory key-value stores.