Amortized cost
Standard · Multiple choice · about 5 min
A hash table starts with 4 buckets and doubles whenever the load factor passes 0.75. A resize rehashes every key, so one resize of n keys costs O(n). You insert n keys. What is the cost per insert, averaged over all n inserts?
Learn the idea first: Load factor and resizing, a visual lesson.
More Load factor and resizing problems
- New positions after resize Warm-up
- Choose the threshold Warm-up
- Count the resizes Standard
- Total rehash moves Standard
- Implement resize Challenge