Computer Science
Explainer
Load Factor: When a Hash Table Must Grow
Your hash table is fast today. Keep inserting and it quietly slows down.
Quick check · tap an answer to continue
Lesson notes
Key points
- The load factor, written alpha, is the number of stored keys divided by the number of buckets in the table.
- With chaining, the expected search cost is about one plus alpha, so a fuller table means longer chains to scan.
- When alpha passes a chosen threshold, the table allocates a bigger array and reinserts every key using the new size, which is called rehashing.
- One rehash costs O(n), but doubling makes it rare, so the amortised cost per insertion stays O(1).
Takeaway: Keep α low by doubling and rehashing; inserts stay amortised O(1).
Quick check: A table has 20 keys in 8 buckets. What is its load factor?
- 0.4
- 2.5
- 160
α = n ÷ m = 20 ÷ 8 = 2.5.
Load factorCost grows with αRehashingAmortised O(1)
Lessons like this, for your syllabus.
Short narrated study videos written for your course, level and exam. Free to start.
Get lessons for your own syllabus