Basis Lab

Answers · The mathematics underneath

How does having more items than slots guarantee that two of them share a slot?

In shortIf you put more items into fewer slots, at least one slot must hold two, because if every slot held at most one you could not fit them all.

It is a certainty, not a probability. If more items are placed into fewer slots, at least one slot must hold two items, because if every slot held at most one there would not be enough slots to hold them all. The conclusion follows from counting alone; it does not depend on how the items are distributed, which is why it is a guarantee rather than a likelihood.

Suppose no slot holds two. Then each of the k slots holds at most one, so the total number of items is at most k. But n>k. Contradiction.\text{Suppose no slot holds two. Then each of the } k \text{ slots holds at most one, so the total number of items is at most } k. \text{ But } n>k. \text{ Contradiction.}

The smallest case shows the whole argument. Thirteen people, twelve months. Suppose no two share a month. Then January holds at most one person, February at most one, and so on through December. Adding those twelve caps gives at most twelve people in the room. But the room holds thirteen, so the supposition is false: some month holds at least two people. Nothing was assumed about which months are likely, or about the people. The same line works with any labels: days of the year, hash buckets, possible friend counts. It is not an averaging argument either. It does not say that on average a slot has n/kn/k items. It says that the fullest slot has at least n/kn/k rounded up, which is a statement about the worst slot.

In general, n items in k slots force some slot to hold at least ⌈nk⌉ items.⌈1312⌉=2,⌈2512⌉=3.\text{In general, } n \text{ items in } k \text{ slots force some slot to hold at least } \left\lceil \frac{n}{k} \right\rceil \text{ items.} \quad \left\lceil \frac{13}{12} \right\rceil = 2, \quad \left\lceil \frac{25}{12} \right\rceil = 3.

The ceiling is the arithmetic. If n=25n=25 and k=12k=12, then 25/1225/12 is a little over 2, so the ceiling is 3. Suppose no month held three people. Then each month held at most two, so twelve months could hold at most 24 people. But there are 25, so some month holds at least three. That is stronger than two sharing: it names how many must pile up in one slot. The same calculation with 1000 people and 365 days gives ⌈1000/365⌉=3\lceil 1000/365 \rceil = 3, so three people share a day of the year. With 1,000,000 people and 1,000,000 days, the ceiling is 1, which is true and useless: it says only that some day has at least one person.

FIG 1
items nslots kceiling of n/kwhat is forced
13122two share a slot
25123three share a slot
10003653three share a day of the year
100000010000001some slot has at least one item
233651some day has at least one person

Notice what the ceiling does not say. It does not say which slot is full, or that every slot is used, or that the items are evenly spread. It says at least one slot reaches the ceiling. That is enough to rule out the possibility that every slot holds at most ⌈n/k⌉−1\lceil n/k \rceil - 1. The proof is always the same: assume every slot holds at most one less than the ceiling, multiply by the number of slots, and contradict nn.

Why the natural guess fails

The natural guess is that this is probabilistic, that sharing becomes likely as the number of items approaches the number of slots, and that the guarantee is a statement about chance. It is not. The counting argument above never mentions chance. It rules out the alternative: no sharing. Because it needs no assumption about how items are placed, it can prove impossibility. That is why the same principle settles claims that otherwise invite endless argument, such as no compression scheme shrinking every input: there are fewer short files than long ones, so two inputs must map to the same short file. A probabilistic statement would require a model: each item independently chooses a slot uniformly, or birthdays are evenly spread across months. The pigeonhole argument requires no model. It works if every item chooses the same slot, if the slots have different sizes, if the labels are chosen adversarially. That is why it is a certainty. The price of needing no model is that the conclusion is weak: it tells you a collision exists, not how many collisions there are, not which items collide, and not how likely a collision is in a random placement. Probability enters only when you ask a different question: what is the chance that no two share? For birthdays, that chance falls below one half at twenty three people, since 1.18 times the square root of 365 is about 22.5. Certainty needs 366 people, one more than the number of days. The guarantee and the threshold are on different scales.

nhalf≈1.18k.1.18365≈22.5.n_{\text{half}} \approx 1.18\sqrt{k}. \quad 1.18\sqrt{365} \approx 22.5.

Where it stops being useful

The guarantee is a floor on the worst case, not a forecast of the typical case. Put one million items into one million slots. The principle says some slot holds at least one item, which is true and useless. The typical case, assuming items fall independently and uniformly, has about 368,000 empty slots (one million divided by ee, approximately 367,879), about half a million colliding pairs (one million squared divided by two million), and a fullest slot holding several items. Those numbers need the uniformity assumption. The certainty does not, which is why it can prove that two items must share, and why it cannot tell you how often that will happen or how bad it will be. For a hash table with a thousand buckets and a thousand items, the guarantee says only that at least one bucket has an item. In fact collisions are everywhere: the expected number of empty buckets is 1000/e1000/e, about 368, and the expected number of colliding pairs is 10002/(2⋅1000)=5001000^2/(2\cdot 1000)=500. That is why hash tables are built to handle collisions with chains or probing rather than to avoid them. If you need to know whether a collision is likely, you need the square root rule and a distribution. If you need to know that a collision exists, the pigeonhole count is enough.

Worth keeping

  • More items than slots forces a shared slot, with no assumption about how the items are distributed.
  • The general bound is that n items in k slots force some slot to hold at least n divided by k rounded up.
  • The certainty says nothing about how likely a collision is; that needs a distribution and happens near the square root of the slot count.

Where this goes next

This question is one step of Counting Without Listing, a course that works through its subject from the beginning. The page that teaches this part of it is More Things Than Places, and it reads the whole way through whether or not you have an account.

What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.

Read that pageThe whole course

Other questions people ask about this

  1. Why is 0! equal to 1?Zero factorial is one because there is exactly one way to arrange nothing: the empty arrangement, with nothing left to place.
  2. How come lining up only some of the things still involves factorials?Because you multiply only the choices for the places you fill, so a partial line-up is a factorial with the unused tail divided out.
  3. Why do I divide by k! when the order doesn't matter?You divide by the number of ways to order the chosen items, because the ordered count listed every chosen group that many times.
  4. Why do I have to subtract the overlap when I add two groups together?Because anything in both groups gets counted twice, so you take one copy back out to leave it counted once.
  5. What is the difference between variance and standard deviation?They measure the same spread: variance is the average squared distance from the mean, standard deviation is its square root, so you report the standard deviation and calculate with the variance.
  6. How do you make a vague claim precise enough to tell whether it's true?Fix what is being talked about, what is asserted, which cases are covered and the cut-off, then name an observation that would prove it false.

Read alongside