Section 14.9

Load factor

Definition

The load factor of a hash table §14.7 is the number of entries it stores divided by its number of buckets, the positions of its array §14.5: α=n/m\alpha = n / m for nn entries and mm buckets. It measures how full the table is and predicts the average cost of an operation. In open addressing, which stores one entry per bucket, α\alpha is at most 1, and costs rise steeply as it approaches 1. In separate chaining, which keeps a list per bucket, α\alpha can exceed 1 and equals the average list length.

Where it fits

Main entry: Hash table (§14.7).

The Hash table entry explains buckets, collisions and probing. The load factor tells a table when to grow: eight buckets holding six entries give α=6/8=0.75\alpha = 6 / 8 = 0.75, the default threshold above which Java’s HashMap doubles its array. In open addressing, the expected number of buckets that a lookup of a missing key examines rises like this:

α\alpha 0.5 0.75 0.9 0.99
ideal hashing, at most 2 4 10 100
linear probing, about 2.5 8.5 50.5 5000.5

The first row is 1/(1−α)1 / (1 - \alpha), the bound when every probe order is equally likely. The second is Knuth’s approximation 12(1+1/(1−α)2)\frac{1}{2}(1 + 1 / (1 - \alpha)^2) for linear probing, which tries the next bucket after a taken one. From 90 to 99% full, the linear-probing cost grows about 100 times.

A table with a fixed number of buckets, common on small devices that avoid dynamic memory, meets a hard limit in open addressing. With m=8m = 8 and 8 entries, α=1\alpha = 1: an insertion finds no free bucket, and a lookup of a missing key examines all 8 buckets, because no never-used bucket remains to stop it. Code that probes until it finds an empty bucket then loops forever. A correct table stops after mm probes, rejects insertions beyond a chosen maximum load, and counts tombstones, the markers that removals leave, as taken when it judges how full it is. With separate chaining, a fixed table can hold more entries than buckets while list nodes last, but every lookup slows as α\alpha grows.

Limits and common mistakes

The load factor is an average. It says nothing about how the entries are spread: a table at α=0.5\alpha = 0.5 whose entries all sit in one bucket or one run behaves like a full table for the keys that land there.

The nominal capacity is not the usable capacity. A table that must answer within a fixed number of probes needs a maximum load well below 1, so its memory must be sized for that load, not for the expected number of entries.

Questions answered

What happens when a fixed-capacity table approaches full occupancy?

As a fixed-capacity hash table approaches full occupancy, its operations slow sharply, and when it is full an open-addressing table, which stores one entry per bucket, cannot accept another key. Under ideal hashing, where every order of trying buckets is equally likely, the expected number of buckets that a lookup of a missing key examines is at most 1/(1−α)1 / (1 - \alpha), where the load factor α\alpha is entries divided by buckets: 10 buckets at 90% full and 100 at 99%. Linear probing, which tries the next bucket after a taken one, is worse, about 50 at 90% full. When every bucket is taken, a lookup of a missing key examines every bucket, and a loop that waits for an empty bucket never ends.

A sound design bounds every probe loop by the number of buckets, sets a maximum load below 1 and rejects or reports insertions beyond it, counts the markers left by removals as taken, and sizes the table for the load at which its slowest lookup is still acceptable. A separate-chaining table, which keeps a list per bucket, has no hard limit from its bucket count, but its lists grow and every lookup slows in proportion.

Related entries: Hash table (§14.7), Worst-case versus average-case complexity (§14.3).