Why is the hash table resized by doubling it?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Hash tables are often resized by doubling because that strategy keeps insertions efficient in the long run without resizing too frequently. The real goal is not the number 2 itself, but maintaining a reasonable load factor while preserving amortized constant-time behavior for inserts and lookups.
Load factor is the trigger
The load factor is:
As the table fills up, collisions become more common. Whether the implementation uses chaining or open addressing, performance gets worse when too many keys compete for too few buckets.
So a hash table usually resizes once the load factor crosses a threshold such as 0.75.
Why doubling is a practical growth rule
If the table grew by only one bucket each time it filled, it would need to rehash constantly. Rehashing is expensive because every existing entry must be placed into the new bucket array.
Doubling reduces how often that full rebuild happens. Suppose a table grows like this:
The number of resizes is logarithmic in the number of stored elements. That means the expensive rehash operations are spaced out enough that the average insertion cost remains low.
This is the same amortization idea used by dynamic arrays.
Amortized cost is the real reason
Resizing a hash table is an O(n) operation because all existing entries must be redistributed. But if resizing happens only occasionally, that cost can be spread over many cheap inserts.
That leads to amortized O(1) insertion.
A rough intuition:
- most inserts go straight into the current table
- only rare inserts trigger a resize
- each element gets moved only a small number of times over the life of the table
Doubling is large enough to make resizes infrequent, but not so large that memory waste becomes absurd.
Why not triple or grow by a fixed number?
Growing by a fixed amount is usually too slow asymptotically because it causes too many full-table rehashes.
Growing by a much larger factor than 2 is possible, but it trades more memory for fewer resizes. In many general-purpose hash tables, doubling is a good compromise:
- simple to implement
- good amortized performance
- moderate memory growth
So doubling is not a mathematical law. It is an engineering tradeoff that works well.
Resizing is more than allocating a bigger array
When the bucket count changes, the bucket index for each key usually changes too, because the table computes bucket positions relative to the current capacity.
That means resizing requires rehashing or at least recomputing the bucket placement for every stored key:
This is why resizing is expensive enough that we want it to happen rarely.
Common Pitfalls
The biggest mistake is thinking doubling is about magical distribution properties by itself. The real reason is amortized performance under a load-factor policy.
Another mistake is ignoring the collision strategy. Chaining and open addressing have different performance curves, but both still suffer when the table becomes too crowded.
Developers also forget that a resize changes bucket positions. You cannot just copy pointers into a bigger array and assume the old indices remain valid.
Finally, do not treat doubling as universal. Some implementations use primes, growth factors other than 2, or incremental resizing. The principle is controlled geometric growth, not worship of one exact number.
Summary
- Hash tables resize to keep the load factor low enough for fast operations.
- Doubling is a common growth rule because it makes expensive rehashes infrequent.
- That gives amortized
O(1)insertion even though individual resizes costO(n). - Fixed-size growth causes too many rebuilds, while much larger growth wastes memory.
- The important idea is geometric growth with a load-factor threshold, not the number
2alone.
Related reading
- Why is the runtime of the selection algorithm On?
- Why is the runtime to construct a decision tree mnlogn?
- Why is the runtime to construct a decision tree mnlogn?
- Why is the size 127 prime better than 128 for a hash-table?
- Why is the time complexity of both DFS and BFS O V E
- Why is the topics argument of KafkaUtils.createStream() a Map rather then array?
- Why is the time complexity of this example from Cracking the Coding Interview Ok ck?
- Why is this called backtracking?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.