Lesson 32 of 86IntermediatePro Interactive Lesson

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

MetricComplexity
Time ComplexityO(1) amortized insert, O(n) rehash
Space ComplexityO(n)
Topic ChapterChapter 6: Hashing
Difficulty LevelIntermediate

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.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.