MAS334 Combinatorics

4. The pigeonhole principle

Remark 4.1.

Let A be a finite set, with |A|=n say. Suppose we have a sequence a1,,am of elements of A, with m>n. As A only has n elements, it is clearly impossible for all the elements ai to be different. Thus, we can find i<j with ai=aj.

Proposition 4.2 (Pigeonhole principle).

Let A be a finite set, with |A|=m say. Suppose we have a list of subsets P1,,Pn (called pigeonholes) such that every element of A lies in one of these subsets. Suppose that m>n (so the number of elements is greater than the number of pigeonholes). Then there exists i such that |Pi|>1.

Proof.

List the elements of A as a1,,am. Each element ai lies in some pigeonhole, so we can choose ki[1,n] such that aiPki. We now have a sequence k1,,km in [1,n]. As m>n, these numbers cannot all be different, so we can choose i<j such that ki=kj=p say. This means that aiPp and ajPp, so |Pp|>1. ∎

Problem 4.3.

Show that there are two people in the world with the same number of hairs.

Solution.

Let N be the number of people in the world, so N7.5×109. Let M be the maximum number of hairs that anyone has. A typical person has about 105 hairs, so it would be safe to assume that M<106, and certainly M is very much smaller than N. Let hi be the number of hairs on the i’th person, so hi[0,M]. The sequence h1,,hN is much longer than the size of the set [0,M], so there must exist i<j such that hi=hj as claimed.

As another way to say essentially the same thing, we can divide all people into pigeonholes H0,,HM, where Hr is the set of people with r hairs. The number of pigeonholes is smaller than the number of people, so there must be some pigeonhole that contains two people. If Hr contains two people, then those two people have the same number of hairs.

Proposition 4.4.

Suppose that people p1,,pn have a meeting, and some of them shake each others hand. (No one shakes their own hand, and no pair of people shake hands more than once.) Then there are two people who shake the same number of hands.

Proof.

Let di be the number of hands shaken by person pi. There are n-1 people whose hands pi could shake, so 0pin-1. In other words, if we put N={0,1,,n-1}, then piN. Note also that because we start at zero, we have |N|=n. Now suppose, for a contradiction, that the numbers di are all different. We now have n different numbers d1,,dn all living in the set N of size n, so the numbers di must fill the whole set N. In particular, we must have n-1=da for some a, and 0=db for some b. Because da=n-1 we see that person pa shakes everyone else’s hand. Because db=0, we see that pb shakes no-one else’s hand. This is a contradiction, because pa shakes pb’s hand. Thus, the numbers di cannot all be different, after all. Thus, we have di=dj for some ij, so pi and pj shake the same number of hands. ∎

Problem 4.5.

Let U be a set of 8 integers, with all the members of U between 1 and 32 (inclusive). Show that there are two distinct disjoint subsets of U with the same sum.

Solution.

As |U|=8, the number of subsets of U is 28=256. Let these subsets be A1,A2,,A256, and let sk be the sum of the elements of Ak. Note that sk is the sum of 8 distinct terms, each of which is between 1 and 32. The largest possible sum of this form is 32+31+30+29+28+27+26+25=228. (We can just do this addition by hand, or use the arithmetic progression rule: we have 8 equally spaced terms between 25 and 32, so the average is 25+322 and the total is 8×25+322=228.) We thus have 256 numbers s1,,s256 lying in the set S={0,,228}. As |S|=229<256, there is not enough space for the numbers sk to all be different. We can therefore find indices pq such that sp=sq. In other words, the sets Ap and Aq are different, but they have the same sum. However, we have not yet solved the problem, because we were supposed to find disjoint subsets. However, this is easily fixed. We put X=ApAq and Y=AqAp and Z=ApAq, so we have a Venn diagram as follows:

It is then clear that X and Y are distinct, disjoint subsets with the same sum. (In a bit more detail, we can let x be the sum of all elements of X, and similarly for y and z. We then have sp=x+z and sq=y+z. We chose p and q such that sp=sq, and it follows that x=y as required.)

Remark 4.6.

The above discussion is carefully phrased to work around the following finicky point: it is possible for two sets X and Y to be disjoint but not distinct, if they both happen to be empty. However, in the proof we have ApAq so at least one of X and Y must be nonempty, and they have the same sum, so both must be nonempty.

Problem 4.7.

Consider a sequence x1,,xn of integers. Show that there is a consecutive subsequence xp,xp+1,,xq (for some pq) such that xp++xq is divisible by n.

Proof.

For 0in we put

yi=(j=1ixi)(modn){0,1,,n-1},

so y0=0 and y1=x1(modn) and y2=(x1+x2)(modn) and so on. This gives n+1 numbers y0,,yn, all lying in the set {0,,n-1}, which has size n. This means that the numbers yi cannot all be different, so we can find indices m<q such that ym=yq. Now note that

ym =x1++xm(modn)
yq =x1++xm+xm+1++xq(modn)
yq-ym =xm+1++xq(modn).

We chose m and q so that ym=yq, and it follows that xm+1++xq=0(modn). In other words, if we take p=m+1q, we find that xp++xq is divisible by n. ∎

Problem 4.8.

Suppose that I deposit money in my piggybank every day for 30 days. On 15 of the days I deposit £1, and on each of the other 15 days I deposit £2. Given an integer k with 1k15, show that there is a sequence of consecutive days during which I deposit precisely k pounds.

Remark 4.9.

For small values of k, we can give a direct argument.

  • For k=1: There are 15 days on which I deposit £1, and any one of those days counts as a sequence of length one during which I deposit precisely £1.

  • For k=2: There are 15 days on which I deposit £2, and any one of those days counts as a sequence of length one during which I deposit precisely £2.

  • For k=3: At some point I must swap over between depositing £1 and £2. Thus, for some i, I deposit £1 on day i, and £2 on day i+1, or vice versa. Either way, {i,i+1} is a sequence of consecutive days over which I deposit precisely £3.

  • For k=4: As there are 15 days on which I deposit £2, I can certainly find a day i when I deposit £2 that is not the beginning or end of the month, so 1<i<30. If I deposit £2 on day i-1, then {i-1,i} is a sequence of consecutive days over which I deposit precisely £4. If I deposit £2 on day i+1, then {i,i+1} is a sequence as required. If neither of these possibilities occur, then I must have deposited £1 on days i-1 and i+1, so {i-1,i,i+1} is a sequence as required.

This is clearly becoming increasingly unwieldy, so it is better to take a less direct approach.

Solution.

Let xi be the amount deposited on day i, so xi{1,2} for i=1,,30. Let yi be the total deposited up to and including day i, so yi=x1++xi. We also put y0=0. Note that y30 is the total amount deposited over the whole month, which is 15×1+15×2=45. Because some money is deposited every day, we have

0=y0<y1<y2<<y30=45.

In particular, the numbers yi are all different, so the set Y={y0,,y30} has size 31. Now suppose we are given k with 1k15. We put Z={y0+k,,y30+k}, and note that this also has size 31. Because yi45 and k14 we have yi+k60. We now see that Y and Z are both subsets of the set N={0,1,,60}, which has size 61. If Y and Z were disjoint, we would have |YZ|=|Y|+|Z|=62, which is impossible, as YZ is a subset of N. It follows that Y and Z are not disjoint, so we can choose mYZ. As mY, we have m=yq for some q. As mZ, we have m=yp+k for some p, so yq=yp+k. This means that we must have p<q, and

xp+1++xq=(x1++xq)-(x1++xp)=yq-yp=k.

Thus, over the sequence of days {p+1,,q}, I deposit precisely k pounds.