The pigeonhole principle, with proofs and worked examples
If more pigeons than pigeonholes fly home, some hole gets at least two pigeons. That is the whole pigeonhole principle, and it is almost too obvious to state. Yet it proves that two Londoners have exactly the same number of hairs, that every hash function has collisions, and that every long enough sequence hides a long increasing or decreasing run.
On this page
The statement
If objects are placed in boxes and , then at least one box contains at least two objects.
Generalised form. If objects are placed in boxes, then some box contains at least objects.
In the language of functions: if , no function is one-to-one. Some two different elements have .
The principle tells you that a crowded box exists, but not which one. That makes it a typical non-constructive argument: it proves existence without exhibiting the example.
Why it is true
Suppose every box held at most objects. Then the total would be at most
because . That is fewer than the objects we placed, a contradiction. The bound is the best possible: dealing the objects round-robin, one per box in turn, puts at most in any box. Try both ways below.
The art: choosing pigeons and holes
Every pigeonhole proof comes down to one decision: what are the pigeons, and what are the holes? The objects are usually the things you are given; the boxes are the possible values of some property you choose. Once you have more objects than possible values, two objects share a value, and the trick is to pick a property for which sharing a value gives you what you want.
Socks in the dark
A drawer holds black and white socks. How many must you take, without looking, to be sure of a matching pair? Pigeons: the socks you take. Holes: the 2 colours. With 3 socks, two share a colour. With 2 you might be unlucky. With colours you need socks.
Shared birthdays
Among 367 people, two share a birthday (366 possible dates, including 29 February). That is certain. The famous birthday paradox is the probabilistic cousin: with only 23 people, the chance of a shared birthday is already about 50.7%, because there are pairs that could match.
Two people with the same number of hairs
A human head has at most about 150,000 hairs, so there are at most 150,001 possible hair counts (counting zero). London has about 9 million people, far more than 150,001, so two Londoners have exactly the same number of hairs. The generalised form says more: some hair count is shared by at least = 60 people.
A card trick bound
From any 13 cards, at least = 4 are of the same suit. From any 5 cards, two share a suit, which is the starting point of a well-known two-person card trick.
Classic proofs
Subset sums: some block of consecutive terms is divisible by n
Claim. Among any integers , some non-empty block of consecutive terms has a sum divisible by .
- Form the prefix sums . That is numbers: the pigeons.
- Look at each . There are only possible remainders, : the holes.
- pigeons in holes: two prefix sums and with leave the same remainder.
- Then is divisible by . It is non-empty because .
Five points in a square: two are close
Claim. Among any 5 points in a square, two are at distance at most .
- Cut the square into four squares by joining the midpoints of opposite sides. These are the holes; the 5 points are the pigeons.
- 5 points, 4 small squares: two points lie in the same small square (a point on a cut line can go in either).
- The farthest apart two points in a square can be is the diagonal, .
Friends at a party
Claim. At any party of people, two people have the same number of friends at the party (friendship is mutual).
- Each person has between and friends: possible values for people. That is not yet enough pigeons.
- But 0 and cannot both occur: someone with friends is friends with everyone, so nobody has 0.
- So the counts take at most different values, and people means two share a count.
Erdős–Szekeres: order in any sequence
Any sequence of distinct numbers contains an increasing subsequence of length or a decreasing one of length . Ten numbers, for instance, always contain a monotone run of four, not necessarily adjacent.
The proof labels each term with a pair : the length of the longest increasing and longest decreasing subsequence ending at . Two different terms never get the same pair. If and , then extends every increasing run ending at , so ; if , likewise . If every run had length at most , there would be only possible pairs for terms: pigeonhole, contradiction. Check the labels yourself:
Pigeonholes in computer science
- Hash collisions are unavoidable. A hash function maps a huge (often infinite) set of inputs to a fixed number of outputs, such as , so many inputs share each output. Security rests on collisions being hard to find, never on their not existing.
- No lossless compressor shrinks every file. There are files of bits but only shorter files. A compressor that made every -bit file shorter would send two files to the same output, and could not decompress both.
- Finite automata cannot count. A DFA with states reading visits some state twice, so it cannot tell those prefixes apart. That is the heart of the proof on the finite-state machines page that is not regular, and of the pumping lemma.
- Loops in a finite state space. A deterministic process with possible states must repeat a state within steps, and then cycles forever. Floyd’s tortoise-and-hare cycle detection and the analysis of pseudo-random generators both start here.
Exercises
Exercise 1: numbers that divide each other
Choose any 51 numbers from . Show that one of them divides another.
- Write each number as with odd. The odd part is one of the 50 odd numbers : the holes.
- 51 numbers, 50 odd parts: two chosen numbers share an odd part, say and with .
- Then the first divides the second. With 50 numbers it can fail: has no such pair.
Exercise 2: equal differences
Show that among any 6 integers, two have a difference divisible by 5.
- Holes: the 5 remainders mod 5. Pigeons: the 6 integers.
- Two integers and leave the same remainder, so .
Exercise 3: how many to guarantee three?
How many people must be in a room to be sure that at least three were born in the same month?
- We want , that is .
- So 25 people suffice. 24 do not: two born in each month is possible. Answer: 25.
References
- P. Erdős and G. Szekeres, “A combinatorial problem in geometry”, Compositio Mathematica 2, 1935.
- K. H. Rosen, Discrete Mathematics and Its Applications, 8th ed., McGraw-Hill, 2019. Section 6.2.
- “Pigeonhole principle”, Wikipedia.