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,…,Ak be finite, disjoint sets (i.e. finite sets such that, for i=j , Ai∩Aj=∅ ). Then ∣⋃i=1kAi∣=∑i=1k∣Ai∣ .
The product rule: Let S be a set of ordered k -tuples (s1,s2,…,sk) such that, for each i=1,2,…,k and each possible choice of s1,s2,…,si−1 , there are ni possible choices for si . Then ∣S∣=n1n2⋯nk .
The counting lemma: Let A and B be finite sets and let ψ:A→B be a function such that, for every b∈B , ∣ψ\inv(b)∣=r . Then ∣B∣=∣A∣/r . (Here ψ\inv(b)={a∈A:ψ(a)=b} .)
We have n different types of object and we want to put r 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 . In general, the number of arrangements of r things from a set of n things with replacement is
nr.Example 6.1.Link copiedHow many car number plates can be made up out of 3 letters (′A′,…,‘Z′ ) followed by 4 digits (‘0′,…,‘9′ )
Given a set X , an r -permutation of X is an arrangement of r of the elements of X in order, with no repetition of elements. We denote the number of r -permutations of a set with n elements by P(n,r) . By the product rule, there are n(n−1)(n−2)⋯(n−r+1)r -permutations of X . So we have
P(n,r)=n(n−1)(n−2)⋯(n−r+1)=(n−r)!n!.
In the case r=n , we simply refer to a permutation of X . The number of permutations of an n -element set is P(n,n)=n! .
Example 6.2.Link copiedIn how many ways can we choose a chairperson, vice-chairperson, secretary, and treasurer from a group of 10 persons? Example 6.3.Link copiedImagine 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 copiedThree 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?
In many cases, we do not want to consider all the permutations of X 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!=6 .
Suppose that the elements of a set X are partitioned into k disjoint sets X1,X2,…,Xk with ∣Xi∣=ni .
We wish to count the number of types of arrangement of the elements of X , in which two arrangements are deemed to be of the same type if the corresponding terms come from the same set Xi .
We let A denote the set of arrangements of the elements of X , and B the set of types of arrangement.
If ψ:A→B is the function which takes a given arrangement to its type, then, for every b∈B , ∣ψ\inv(b)∣=n1!n2!⋯nk! .
So by the counting lemma we have
∣B∣=n1!n2!⋯nk!∣A∣=n1!n2!⋯nk!n!. Example 6.5.Link copiedHow many strings can be formed using the following letters?
WHANGAMOMONA
Example 6.6.Link copiedHow 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 copiedA 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.8Three 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 r -tuple of elements of a set X , we are going to choose an r -element subset of X . We denote the number of r -element subsets of an n -element set by C(n,r) , or (rn) .
To calculate (rn) , let X be an n -element set, let A be the set of r -permutations of X and let B be the set of r -element subsets of X . Define ψ:A→B by
ψ((x1,x2,…,xr))={x1,x2,…,xr}.
Then, for any Y∈B , ψ\inv(Y) is the set of permutations of Y , which has cardinality P(r,r)=r! . So, by the counting lemma, we have
(rn)=∣B∣=r!∣A∣=(n−r)!r!n!.
The numbers (rn) are called binomial coefficients. Some of their properties are given in section 6.5.
Example 6.9.Link copiedAn 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 copiedIn a non-standard set of 40 playing cards (10 cards of 4 different suits) how many distinct four-card hands contain cards comprising of exactly
Example 6.11.Link copiedSuppose 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 copiedA certain class consists of 16 men and 13 women. How many different committees can be chosen from this class if the committees consist of:
(a) 9people?
(b) 5men and 4 women?
(a) 9men or 9 women?
Solution.
(a) (929)=10,015,005 .
(b) (516)×(413)=3,123,120 .
(c) (916)+(913)=11,440+715=12,155 .
Example 6.13.Link copiedHow many routes are there from the lower left corner of an n×n square grid to the upper right corner if we are restricted to traveling only to the right or upward? Example 6.14.Link copiedAn 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 i brown marbles,
j blue marbles and p yellow marbles corresponds to the sequence of i 0s followed by a 1 followed by j 0s followed by a 1 followed by p 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 (27) .
In general, the number of ways of selecting n objects from k types, with order unimportant but with repetition allowed, is
(k−1n+k−1).
= number of ways of selecting n objects of k different types
= number of ways of placing n indistinguishable objects into k bijections
= number of ways of arranging n objects and k−1 dividers
In Section 6.5 we learn that
(k−1n+k−1)=(nn+k−1) .
If k is greater than n then it is easier to calculate the expression to the right.
Example 6.15.Link copiedA 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
16 muffins?
16 muffins with at least one of each kind?
16 muffins with at least two peach and at least three chocolate?
16 muffins with no more than two broccoli?
16 muffins with at least two cheese, at least three chocolate and no more than two broccoli muffins?
(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 copiedA math lecturer is about to assign grades of A , B , C or D , where D is a failing grade, to his class of 100 students. How many different grade distributions are possible if:
Any distribution is allowed.
No more than 80% of the students may pass.
No fewer than 50% of the students may pass.
No more than 20% of the students may get A grades.
Conditions 2, 3 and 4 apply.
Example 6.18.Link copiedA generous eccentric withdraws $700 in $100 notes from the bank. He meets 3 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 3 strangers?
(b)In how many ways can the money be distributed among the 3 strangers if each stranger gets at least $100?
Solution.
(a)(3−17+3−1)=36 .
(b)(3−14+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 (kn) . First, the reason for the name.
Fact 1: for any real numbers a and b , and any n∈N ,
(a+b)n=∑k=0n(kn)an−kbk.
This is the binomial theorem. We will prove this later, using induction and Fact 3 (below).
Fact 2: For any n∈N and k∈{0,1,…,n} ,
(kn)=(n−kn)and(0n)=(nn)=1.
This is because the number of ways of selecting k objects is the same as the number of ways of selecting which n−k objects to omit.
Fact 3 (Pascal’s Identity): For any n∈N and k∈{0,1,…,n} ,
(k+1n+1)=(k+1n)+(kn).
This is because we can choose k+1 of the n+1 objects either by choosing k+1 of the first n objects or by choosing k of the first n objects together with the (n+1)th object.
We know that if A and B are disjoint sets then ∣A∪B∣=∣A∣+∣B∣ . What if A and B are not disjoint? In counting ∣A∣+∣B∣ , we have counted the elements of A∩B twice, so if we subtract ∣A∩B∣ , we will get the right number. In other words,
∣A∪B∣=∣A∣+∣B∣−∣A∩B∣.
What about three sets A , B and C ? As before, in counting ∣A∣+∣B∣+∣C∣ the elements of A∩B , A∩C , and B∩C will be counted more than once. If we subtract (∣A∩B∣+∣A∩C∣+∣B∩C∣) , we will have dealt properly with elements which are in two of the sets. However, elements of A∩B∩C will have been added three times and
subtracted three times, so we must add them in again to get
∣A∪B∪C∣=
(∣A∣+∣B∣+∣C∣), −(∣A∩B∣+∣A∩C∣+∣B∩C∣) +∣A∩B∩C∣
In general, let A1,A2,…,An be sets. Let I={1,2,…,n} . For 1≤k≤n , let Pk={J⊆I:∣J∣=k} . Then
⋃i=1nAi=∑k=1n[(−1)k−1∑J∈Pk⋂i∈JAi].
This result is known as the inclusion/exclusion principle.
To prove this result, consider the contribution of a typical element x of ⋃i=1nAi to the right hand side of the equation. Suppose that x is in m of the sets, namely Ai1,Ai2,…,Aim . First, fix some k with 1≤k≤n . The contribution of x to ∑J∈Pk⋂i∈JAi is the number of sets in Pk which are subsets of {i1,i2,…,im} , in other words the number of k -element subsets of an m -element set, which is (km) . In particular, x contributes nothing if k>m . So the total contribution of x to the right hand side of (∗ ) is
Link copiedExample 6.20.Link copiedSuppose 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 copiedHow many numbers between 1 and 1000 are divisible by 3, 5 or 7?
Solution. For each n∈P=Z≥1 , let Mn denote the set of numbers between 1 and 1000 which are divisible by n . Then ∣Mn∣=⌊n1000⌋ . Notice that Mm∩Mn=Ml , where l is the least common multiple of m and n . By the inclusion/exclusion principle, we have
Example 6.22.Link copiedAmong 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 m objects (maybe letters or pigeons) are placed into n boxes (called “pigeonholes”), and m>n , then one pigeonhole must receive at least two objects.
In general, if the number of objects is more than k times the number of pigeonholes, then some pigeonhole must contain at least k+1 objects.
In general, if the elements of a set with N elements are partitioned into k subsets, then one of the subsets must contain at least ⌈kN⌉ elements.\
(Note ⌈⌉ is the ceiling function. ⌈x⌉ means take the smallest integer which is greater than or equal to x . For example ⌈9.1⌉=10 .)
Proof: Suppose A is a set with ∣A∣=N , and A is partitioned into subsets A1,A2,…,Ak . In other words, A1,A2,…,Ak are disjoint sets whose union is the whole of A . Let x=kN . Suppose that ∣Ai∣<x for each i . Then
N
=∑i=1k∣Ai∣ <∑i=1kx =kx =N
This contradiction shows that there must be at least one i such that ∣Ai∣≥x . But then, since ∣Ai∣ is an integer, we must have ∣Ai∣≥⌈x⌉ , ie ∣Ai∣≥⌈kN⌉ , as required.
Example 6.23.Link copiedHow 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 copiedSuppose that 83 marbles are to put into 9 bags. Then one bag must receive at least ⌈983⌉=⌈9.22⌉=10 marbles. Example 6.25.Link copiedHow 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 copiedChoose 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 21 . Example 6.27.Link copiedShow that, among a collection of n2+1 objects, there are either n+1 which are identical or n+1 which are all different.
Solution. Let p= ‘the number of sets of identical objects’.
There are now two possibilities, either p≤n or p>n .
(i) Suppose that p≤n , then pn2+1>n , therefore some set of identical objects contains at least n+1 objects. That is, at least n+1 objects are identical.
(ii) Suppose that p>n , then there are at least n+1 sets of identical objects. That is, at least n+1 objects are all different.
Hence, among a collection of n2+1 objects, there are either n+1 which are identical or n+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 copiedLet A⊆{1,2,…,14} with ∣A∣=6 . Show that A has distinct subsets B and C such that the sum of the elements of B equals the sum of the elements of C . Example 6.29.Link copiedAssume 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 copiedDuring 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.