COMPSCI 225:
Discrete Structures in Mathematics and Computer Science

Enumeration

Introduction

In this section we will consider problems involving counting the number of ways that we can choose a number of objects. These basically fall into two types: arrangement problems in which the order in which we make the choices is significant, and selection problems in which the order is not significant.

We have three basic rules in solving these problems.

The union rule: Let A1,A2,,AkA_1,A_2,\dots,A_k be finite, disjoint sets (i.e. finite sets such that, for iji\ne j , AiAj=A_i\cap A_j=\emptyset ). Then i=1kAi=i=1kAi|\bigcup_{i=1}^kA_i|=\sum_{i=1}^k|A_i| .

The product rule: Let SS be a set of ordered kk -tuples (s1,s2,,sk)(s_1,s_2,\dots,s_k) such that, for each i=1,2,,ki=1,2,\dots,k and each possible choice of s1,s2,,si1s_1,s_2,\dots,s_{i-1} , there are nin_i possible choices for sis_i . Then S=n1n2nk|S|=n_1n_2\cdots n_k .

The counting lemma: Let AA and BB be finite sets and let ψ:AB\psi:A\to B be a function such that, for every bBb\in B , ψ\inv(b)=r|\psi\inv(b)|=r . Then B=A/r|B|=|A|/r . (Here ψ\inv(b)={aA:ψ(a)=b}\psi\inv(b)=\{\,a\in A:\psi(a)=b\,\} .)


Arrangement problems

Arrangements with replacement

Link copied

We have nn different types of object and we want to put rr of them in a row. The ordering matters. We have an unlimited supply of each type of object. How many ways can we do this?

This is a straightforward use of the product rule. For example consider 4 consecutive throws of a 6-sided dice. The first throw gives us one out of six numbers, as does the second, third and fourth. Hence the number of possible results is 64\displaystyle 6^4 . In general, the number of arrangements of rr things from a set of nn things with replacement is

nr.n^r.
Example 6.1.Link copied How many car number plates can be made up out of 3 letters (A,,Z'A',\ldots,`Z' ) followed by 4 digits (0,,9`0',\ldots,`9' )

Arrangements without replacement

Link copied

Given a set XX , an rr -permutation of XX is an arrangement of rr of the elements of XX in order, with no repetition of elements. We denote the number of rr -permutations of a set with nn elements by P(n,r)P(n,r) . By the product rule, there are n(n1)(n2)(nr+1)n(n-1)(n-2)\cdots(n-r+1) rr -permutations of XX . So we have

P(n,r)=n(n1)(n2)(nr+1)=n!(nr)!.P(n,r)=n(n-1)(n-2)\cdots(n-r+1)=\frac{n!}{(n-r)!}.

In the case r=nr=n , we simply refer to a permutation of XX . The number of permutations of an nn -element set is P(n,n)=n!P(n,n)=n! .

Example 6.2.Link copied In how many ways can we choose a chairperson, vice-chairperson, secretary, and treasurer from a group of 10 persons?

Example 6.3.Link copied Imagine a row of 5 chairs in a room. There are 7 persons in the room. In how many ways can 5 among them sit on the row of chairs?

Example 6.4.Link copied Three men and three women are going to occupy a row of six seats. In how many different orders can they be seated so that men occupy the two end seats?

Arrangements with repetitions

Link copied

In many cases, we do not want to consider all the permutations of XX as being distinct. For example, if we regard the two Gs in EGG as being identical, then there are only 3 ways to arrange the letters of the word EGG, rather than 3!=63!=6 .

Suppose that the elements of a set XX are partitioned into kk disjoint sets X1,X2,,XkX_1,X_2,\dots, X_k with Xi=ni|X_i|=n_i .

B=An1!n2!nk!=n!n1!n2!nk!.|B|=\frac{|A|}{n_1!n_2!\cdots n_k!}=\frac{n!}{n_1!n_2!\cdots n_k!}.
Example 6.5.Link copied How many strings can be formed using the following letters?

WHANGAMOMONA


Example 6.6.Link copied How many distributions of ten different books are possible if Vanessa is to receive 5 books, Paul is to receive 3 books, and Rachel is to receive 2 books?

Example 6.7.Link copied A playoff between two teams consists of at most five games. No games end in a draw. The first team that wins three games wins the playoff. In how many ways can the playoff occur?

Example 6.8 Three jars of rhubarb jam and three jars of manuka honey are to be put in a row on a shelf. In how many different orders can they be placed so that there is a jar of jam at each end of the shelf?


Selections

We now consider counting problems in which the order we make our choices does not matter. In other words, instead of choosing an ordered rr -tuple of elements of a set XX , we are going to choose an rr -element subset of XX . We denote the number of rr -element subsets of an nn -element set by C(n,r)C(n,r) , or (nr)\binom nr .

To calculate (nr)\binom nr , let XX be an nn -element set, let AA be the set of rr -permutations of XX and let BB be the set of rr -element subsets of XX . Define ψ:AB\psi:A\to B by

ψ((x1,x2,,xr))={x1,x2,,xr}.\psi((x_1,x_2,\dots,x_r))=\{x_1,x_2,\dots,x_r\}.

Then, for any YBY\in B , ψ\inv(Y)\psi\inv(Y) is the set of permutations of YY , which has cardinality P(r,r)=r!P(r,r)=r! . So, by the counting lemma, we have

(nr)=B=Ar!=n!(nr)!r!.\binom nr=|B|=\frac{|A|}{r!}=\frac{n!}{(n-r)!r!}.

The numbers (nr)\binom nr are called binomial coefficients. Some of their properties are given in section 6.5.


Example 6.9.Link copied An ordinary deck of 52 cards consists of four suits (clubs, diamonds, hearts, and spades) of 13 denominations each (ace, 2-10, jack, queen, king).

(a) How many (unordered) five-card poker hands, selected from an ordinary 52-card deck, are there?

(b) How many poker hands contain cards all of the same suit?

(c) How many poker hands contain three cards of one denomination and two cards of a second denomination?


Example 6.10.Link copied In a non-standard set of 4040 playing cards (1010 cards of 44 different suits) how many distinct four-card hands contain cards comprising of exactly

(a) one suit?

(b) two suits?

(c) three suits?

(d) four suits?


Solution.

(a) (41)(104)=840{4\choose1} {10 \choose4} = 840 .

(b) (42)[(103)(101)+(102)(102)+(101)(103)]=26,550{4\choose 2} \left[ {10 \choose3}{10 \choose1} + {10 \choose2}{10 \choose2} + {10 \choose1}{10 \choose3} \right] = 26,550 .

(c) (43)[(102)(101)(101)+(101)(102)(101)+(101)(101)(102)]=54,000{4\choose 3} \left[ {10 \choose2}{10 \choose1}{10 \choose1} + {10 \choose1}{10 \choose2}{10 \choose1} + {10 \choose1}{10 \choose1}{10 \choose2} \right] = 54,000 .

(d) (44)(101)(101)(101)(101)=10,000{4\choose 4} {10 \choose1}{10 \choose1}{10 \choose1}{10 \choose1} = 10,000 .


Example 6.11.Link copied Suppose a class of 12 students is to be divided into four study groups of three students. In how many ways can this be done (a) if the groups study different subjects; (b) if the groups study the same subject?

Example 6.12.Link copied A certain class consists of 1616 men and 1313 women. How many different committees can be chosen from this class if the committees consist of:

(a) 99 people?

(b) 55 men and 44 women?

(a) 99 men or 99 women?

Solution.

(a) (299)=10,015,005{29 \choose 9} = 10,015,005 .

(b) (165)×(134)=3,123,120{16 \choose 5} \times {13 \choose 4} = 3,123,120 .

(c) (169)+(139)=11,440+715=12,155{16 \choose 9} + {13 \choose 9} = 11,440 + 715 = 12,155 .


Example 6.13.Link copied How many routes are there from the lower left corner of an n×nn \times n square grid to the upper right corner if we are restricted to traveling only to the right or upward?

Example 6.14.Link copied An investor is going to invest $16,000 in four stocks chosen from a list of twelve prepared by her broker. How many different investments are possible if

(a) $4000 is to be invested in each stock?

(b) $6000 is to be invested in one stock, $5000 in another, $3000 in the third, and $2000 in the fourth?


Selections with repetitions allowed

Suppose we have a bag containing a large number of marbles in each of three colors: brown, yellow and blue. In how many ways can we select 5 marbles from the bag? In this case we are selecting 5 objects from 3 types, with order unimportant and with repetition allowed.

To answer this question, we will exhibit a 1-1 correspondence between the set of solutions and the set of sequences of 5 0s and 2 1s. The correspondence is as follows: a selection of ii brown marbles, jj blue marbles and pp yellow marbles corresponds to the sequence of ii 0s followed by a 1 followed by jj 0s followed by a 1 followed by pp 0s. For example, the selection “1 brown, 0 blue, 4 yellow” corresponds to the sequence 0110000.

So now we just need to work out how many sequences of 5 0s and 2 1s there are. Well, there are 7 symbols, and we must select the 2 places to put the 1s. So the answer is (72)\binom72 .

In general, the number of ways of selecting nn objects from kk types, with order unimportant but with repetition allowed, is

(n+k1k1).\binom{n+k-1}{k-1}.

= number of ways of selecting nn objects of kk different types

= number of ways of placing nn indistinguishable objects into kk bijections

= number of ways of arranging nn objects and k1k-1 dividers

In Section 6.5 we learn that

(n+k1k1)=(n+k1n)\binom{n+k-1}{k-1} = \binom{n+k-1}{n} .

If kk is greater than nn then it is easier to calculate the expression to the right.


Example 6.15.Link copied A bakery sells 8 varieties of muffins. Apple, banana, blueberry, cheese, chocolate, double chocolate, peach and everyone’s favorite, broccoli. How many ways are there to select
  1. 16 muffins?

  2. 16 muffins with at least one of each kind?

  3. 16 muffins with at least two peach and at least three chocolate?

  4. 16 muffins with no more than two broccoli?

  5. 16 muffins with at least two cheese, at least three chocolate and no more than two broccoli muffins?


Example 6.16.Link copied Donut King makes four different types of donuts.

(a) How many different assortments of one dozen donuts can be purchased?

(b) How many different assortments of one dozen donuts can be purchased that include at least one donut of each type?

(c) How many different assortments of one dozen donuts can be purchased that include no more than three chocolate donuts?


Example 6.17.Link copied A math lecturer is about to assign grades of AA , BB , CC or DD , where DD is a failing grade, to his class of 100 students. How many different grade distributions are possible if:
  1. Any distribution is allowed.

  2. No more than 80% of the students may pass.

  3. No fewer than 50% of the students may pass.

  4. No more than 20% of the students may get A grades.

  5. Conditions 2, 3 and 4 apply.


Example 6.18.Link copied A generous eccentric withdraws $700 in $100 notes from the bank. He meets 33 strangers in the street on his way home and gives all this money away to them.

(a) In how many ways can the money be distributed among the 33 strangers?

(b) In how many ways can the money be distributed among the 33 strangers if each stranger gets at least $100?


Solution.

(a) (7+3131)=36{{7+3 -1} \choose {3-1}} = 36 .

(b) (4+3131)=15{{4+3 -1} \choose {3-1}} = 15 . _First give $100 to each stranger and then share out the remaining $400.


Some properties of binomial coefficients

We now describe some of the facts about the binomial coefficients (nk)\binom nk . First, the reason for the name.

Fact 1: for any real numbers aa and bb , and any nNn\in\N ,

(a+b)n=k=0n(nk)ankbk.(a+b)^n=\sum_{k=0}^n\binom nk a^{n-k}b^k.

This is the binomial theorem. We will prove this later, using induction and Fact 3 (below).

Fact 2: For any nNn\in\N and k{0,1,,n}k\in\{0,1,\dots,n\} ,

(nk)=(nnk)and(n0)=(nn)=1.\binom nk=\binom n{n-k}\qquad\text{and}\qquad\binom n0=\binom nn=1.

This is because the number of ways of selecting kk objects is the same as the number of ways of selecting which nkn-k objects to omit.

Fact 3 (Pascal’s Identity): For any nNn\in\N and k{0,1,,n}k\in\{0,1,\dots,n\} ,

(n+1k+1)=(nk+1)+(nk).\binom{n+1}{k+1}=\binom n{k+1}+\binom nk.

This is because we can choose k+1k+1 of the n+1n+1 objects either by choosing k+1k+1 of the first nn objects or by choosing kk of the first nn objects together with the (n+1)th(n+1)^{\text{th}} object.


Example 6.19.Link copied Let nn be a positive integer. Show that
(n0)+(n1)++(nn1)+(nn)=2n.\binom n0 + \binom n1 +\dots+\binom n{n-1}+\binom nn=2^n.

The inclusion/exclusion principle

We know that if AA and BB are disjoint sets then AB=A+B|A\cup B|=|A|+|B| . What if AA and BB are not disjoint? In counting A+B|A|+|B| , we have counted the elements of ABA\cap B twice, so if we subtract AB|A\cap B| , we will get the right number. In other words,

AB=A+BAB.|A\cup B|=|A|+|B|-|A\cap B|.

What about three sets AA , BB and CC ? As before, in counting A+B+C|A|+|B|+|C| the elements of ABA\cap B , ACA\cap C , and BCB\cap C will be counted more than once. If we subtract (AB+AC+BC)\bigl(|A\cap B|+|A\cap C|+|B\cap C|\bigr) , we will have dealt properly with elements which are in two of the sets. However, elements of ABCA\cap B\cap C will have been added three times and subtracted three times, so we must add them in again to get

ABC=|A\cup B\cup C| =
(A+B+C),\bigl(|A|+|B|+|C|\bigr),
(AB+AC+BC)- \bigl(|A\cap B|+|A\cap C|+|B\cap C|\bigr)
+ABC+ |A\cap B\cap C|

In general, let A1,A2,,AnA_1, A_2,\dots,A_n be sets. Let I={1,2,,n}I=\{1,2,\dots,n\} . For 1kn1\le k\le n , let Pk={JI:J=k}\mathcal P_k=\{\,J\subseteq I:|J|=k\,\} . Then

i=1nAi=k=1n[(1)k1JPkiJAi].\Bigl|\bigcup_{i=1}^n A_i\Bigr|= \sum_{k=1}^n\left[(-1)^{k-1}\sum_{J\in\mathcal P_k}\Bigl|\bigcap_{i\in J}A_i\Bigr|\right].

This result is known as the inclusion/exclusion principle.

Proof of the inclusion/exclusion principle

Link copied

To prove this result, consider the contribution of a typical element xx of i=1nAi\bigcup_{i=1}^n A_i to the right hand side of the equation. Suppose that xx is in mm of the sets, namely Ai1,Ai2,,AimA_{i_1},A_{i_2},\dots,A_{i_m} . First, fix some kk with 1kn1\le k\le n . The contribution of xx to JPkiJAi\sum_{J\in\mathcal P_k}\left|\bigcap_{i\in J}A_i\right| is the number of sets in Pk\mathcal P_k which are subsets of {i1,i2,,im}\{i_1,i_2,\dots,i_m\} , in other words the number of kk -element subsets of an mm -element set, which is (mk)\binom mk . In particular, xx contributes nothing if k>mk>m . So the total contribution of xx to the right hand side of (* ) is

k=1m[(1)k1(mk)]\sum_{k=1}^m\left[(-1)^{k-1}\binom mk\right]
=1(k=0m(mk)(1)k)=1-\left(\sum_{k=0}^m\binom mk(-1)^k\right)
=1(1+(1))m=1-(1+(-1))^m
=1=1

Using the inclusion/exclusion principle

Link copied
Example 6.20.Link copied Suppose that there are 1807 first year students at Auckland University. Of these, 453 are taking a course in biology, 567 are taking a course in chemistry, and 299 are taking courses in both biology and chemistry. How many are not taking a course in either biology or in chemistry?

Example 6.21.Link copied How many numbers between 1 and 1000 are divisible by 3, 5 or 7?

Solution. For each nP=Z1n\in\mathbb{P} = \Z_{\ge 1} , let MnM_n denote the set of numbers between 1 and 1000 which are divisible by nn . Then Mn=1000n|M_n|=\left\lfloor\frac{1000}n\right\rfloor . Notice that MmMn=MlM_m\cap M_n=M_l , where ll is the least common multiple of mm and nn . By the inclusion/exclusion principle, we have


Example 6.22.Link copied Among a group of 200 Auckland University students, 19 study French, 10 study German, and 28 study Spanish. If 3 study both French and German, 8 study both French and Spanish, 4 study both German and Spanish, and 1 studies French, German, and Spanish, how many of these students are not studying French, German, or Spanish?

The pigeonhole principle

In its simplest form, the pigeonhole principle states that if mm objects (maybe letters or pigeons) are placed into nn boxes (called “pigeonholes”), and m>nm>n , then one pigeonhole must receive at least two objects.

General pigeonhole principle

Link copied

In general, if the number of objects is more than kk times the number of pigeonholes, then some pigeonhole must contain at least k+1k+1 objects.

In general, if the elements of a set with NN elements are partitioned into kk subsets, then one of the subsets must contain at least Nk\left\lceil\frac Nk\right\rceil elements.\ (Note \left\lceil\:\:\right\rceil is the ceiling function. x\left\lceil x\right\rceil means take the smallest integer which is greater than or equal to xx . For example 9.1=10\left\lceil 9.1\right\rceil=10 .)

Proof: Suppose AA is a set with A=N|A|=N , and AA is partitioned into subsets A1,A2,,AkA_1,A_2,\dots,A_k . In other words, A1,A2,,AkA_1,A_2,\dots,A_k are disjoint sets whose union is the whole of AA . Let x=Nkx=\frac Nk . Suppose that Ai<x|A_i|<x for each ii . Then

NN
=i=1kAi=\sum_{i=1}^k|A_i|
<i=1kx<\sum_{i=1}^kx
=kx=kx
=N=N

This contradiction shows that there must be at least one ii such that Aix|A_i|\ge x . But then, since Ai|A_i| is an integer, we must have Aix|A_i|\ge\lceil x\rceil , ie AiNk|A_i|\ge\left\lceil\frac Nk\right\rceil , as required.


Example 6.23.Link copied How many students must be in a class to guarantee that at least two students receive the same score on the final exam, if the exam is graded on a scale from 0 to 100 points?

Example 6.24.Link copied Suppose that 83 marbles are to put into 9 bags. Then one bag must receive at least 839=9.22=10\left\lceil\frac{83}9\right\rceil=\lceil9.22\rceil=10 marbles.

Example 6.25.Link copied How many people must be selected from a collection of fifteen married couples to ensure that at least two of the persons chosen are married to each other?

Example 6.26.Link copied Choose any five points from the interior of an equilateral triangle having sides of length 1. Show that the distance between some pair of these points does not exceed 12\frac{1}{2} .

Example 6.27.Link copied Show that, among a collection of n2+1n^2 +1 objects, there are either n+1n+1 which are identical or n+1n+1 which are all different.

Solution. Let p=p= ‘the number of sets of identical objects’.

There are now two possibilities, either pn p \leq n or p>n p > n .

(i) Suppose that pnp\leq n , then n2+1p>n\frac{n^2+1}{p} > n , therefore some set of identical objects contains at least n+1n+1 objects. That is, at least n+1n+1 objects are identical.

(ii) Suppose that p>np > n , then there are at least n+1n+1 sets of identical objects. That is, at least n+1n+1 objects are all different.

Hence, among a collection of n2+1n^2 +1 objects, there are either n+1n+1 which are identical or n+1n+1 which are all different.


Trickier pigeonhole applications

We now give some examples which show how the pigeonhole principle can be used to solve non-trivial problems.

Example 6.28.Link copied Let A{1,2,,14}A\subseteq\{1,2,\dots,14\} with A=6|A|=6 . Show that AA has distinct subsets BB and CC such that the sum of the elements of BB equals the sum of the elements of CC .

Example 6.29.Link copied Assume that in a group of six people, each pair of individuals consists of two friends or two enemies. Show that there are either three mutual friends or three mutual enemies.

Example 6.30.Link copied During a month with 30 days a netball team plays at least 1 game a day, but no more than 45 games. Show that there must be a period of some number of consecutive days during which the team must play exactly 14 games.