Vous êtes sur la page 1sur 52

Getting Started with Combinatorics

K. V. Iyer, Ph.D.
Department of Computer Science and Engg.
National Institute of Technology
Trichy - 620 015
April 2010
For third year B.Tech. students for the core course
3:0 Combinatorics and Graph Theory

First draft
1
Basic Combinatorics K. V. Iyer
Contents
1 Introduction 5
2 Elementary Counting Ideas 6
2.1 Sum Rule and Product Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Combinations and Permutations 8
3.1 Stirlings Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Examples in combinatorial reasoning 10
5 The Pigeon-Hole Principle 14
6 More Enumerations 16
6.1 Enumerating permutations with constrained repetitions . . . . . . . . . . . . . . . 17
7 Ordered and Unordered Partitions 18
7.1 Enumerating the ordered partitions of a set . . . . . . . . . . . . . . . . . . . . . . 18
8 Combinatorial Identities 21
9 The Binomial and the Multinomial Theorems 23
10 Principle of Inclusion-Exclusion 26
10.1 Eulers -function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
10.2 Inclusion-Exclusion Principle and the Sieve of Eratosthenes . . . . . . . . . . . . . 29
11 Derangements 30
12 Partition Problems 32
12.1 Recurrence relations p(n, m) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
12.2 Ferrer Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
13 Solution of Recurrence Relations 34
13.1 Homogeneous Recurrences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
13.2 Inhomogeneous Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
April 2007 2 CSE/NIT
Basic Combinatorics K. V. Iyer
13.3 Repertoire Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
13.4 Perturbation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
14 Solving Recurrences using Generating Functions 44
14.1 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
14.2 Manipulations of generating functions . . . . . . . . . . . . . . . . . . . . . . . . . 46
April 2007 3 CSE/NIT
Basic Combinatorics K. V. Iyer
. . . combinatorics, a sort of gloried dice-throwing . . .
Robert Kanigel in The Man who knew Innity: A life of the genius Ramanujan
Scriber, New York, 1991.
Note 0.1:
These notes, in a preliminary form, are intended for the B.E. students of the rst course on Com-
binatorics and Graph Theory. By no means, these are original! Much of the material is drawn
from contemporary sources, mainly older books; therefore, at the moment I am not looking for
a publisher. I have added acknowledgements in the form of references. Errors are likely to be
present herein - typos and others - students should point out these. No rewards please.
Note 0.2:
The sum rule and the product rule are introduced followed by the notions of permutations and
combinations. Combinatorial reasonings are introduced through examples and typical enumer-
ation problems are introduced. Binomial and multinomial theorems follow. This is followed by
the pigeon-hole principle and the principle of inclusion-exclusion. Subsequently solutions to re-
currence relations are dealt with. Generating functions are then considered.
April 2007 4 CSE/NIT
Basic Combinatorics K. V. Iyer
1 Introduction
Combinatorics is the science (and to some extent, the art) of counting and enumeration of cong-
urations (it is understood that a conguration arises every time objects are distributed according
to certain predetermined constraints). Just as arithmetic deals with integers (with the standard
operations), algebra deals with operations in general, analysis deals with functions, geometry deals
with rigid shapes and topology deals with continuity, so does combinatorics deals with congu-
rations. The word combinatorial was rst used in the modern mathematical sense by Gottfried
Wilhelm Leibniz (16461716) in his Dissertatio de Arte Combinatoria (Dissertation Concerning
the Combinatorial Arts). Reference to combinatorial analysis is found in English in 1818 in the
title Essays on the Combinatorial Analysis by P. Nicholson (see Je Millers Earliest known uses
of the words of Mathematics, Soc. Ind. Appl. Math., U.S.A.). In his book [?], C. Berge points
out the following interesting aspects of combinatorics:
study of the intrinsic properties of a known conguration.
investigation into the existence/non-existence of a conguration with specied properties.
counting and obtaining exact formulas for the number of congurations satisfying certain
specied properties.
approximate counting of congurations with a given property.
enumeration and classication of congurations.
optimization in the sense of obtaining a conguration with specied properties so as to
minimize an associated cost function.
It is instructive to retain the above guidelines and look for specic examples that illustrate each
aspect mentioned above. According to L.Lovasz (see the preface to his problem book (1979)),
Having vegitated on the fringes of mathematical science for centuries, combinatorics has now
burgeoned into one of the fastest growing branches of mathematics undoubtedly so if we consider
the number of publications in this eld, its applications in other branches of mathematics and
in other sciences, and also, the interest of scientists, economists and engineers in combinatorial
structures . Basic combinatorics is now regarded as an important topic in Discrete Mathematics.
Principles of counting appear in various forms in Computer Science and Mathematics, especially
in the analysis of algorithms, in graph theory and in probability theory.
April 2007 5 CSE/NIT
Basic Combinatorics K. V. Iyer
2 Elementary Counting Ideas
We begin with some simple ideas of counting using the sum rule, the product rule and obtaining
permutations and combinations of nite sets of objects.
2.1 Sum Rule and Product Rule
The sum rule or the principle of disjunctive counting. If a nite set X is the union of pairwise
disjoint nonempty subsets S
1
, S
2
, . . . , S
n
, then [X[ = [S
1
[ +[S
2
[ + +[S
n
[ where, [X[ denotes
the number of elements in the set X.
The product rule or the principle of sequential counting. If S
1
, S
2
, . . . , S
n
are nonempty nite sets,
then the number of elements in the cartesian product S
1
S
2
S
n
is [S
1
[ [S
2
[ [S
n
[.
For instance, consider the sets A = p, q, r, s, t and B = u, v, w. The cardinality [A B[
of the set A B is [A[ [B[ = 5.3 = 15. The proof of the product rule is straightforward. One
way to do it is to prove the rule taking two sets and then use induction on the number of sets.
The sum rule and the product rule are basic and they are applied mechanically in many
situations.
Example 2.1:
Assume that a car registration system allows a registration plate to consist of one, two or three
English alphabets followed by a number (not zero or starting with zero) having a number of digits
equal to the number of alphabets. How many possible registrations are there?
There are 26 possible alphabets and 10 possible digits, including 0. By the Product Rule
there are 26, 26 26 and 26 26 26 possibilities of alphabet combination(s) of length 1,2
and 3 respectively and 9, 9 10 and 9 10 10 permissible numbers. Each occurrence of a
single alphabet can be combined with any of the nine single digit numbers 1 to 9. Similarly each
occurrence of a double (respectively triple) alphabet canbe combined with any of the allowed
ninety two digit numbers from 10 to 99 (respectively nine hundred three digit numbers from 100
to 999).Hence the number of registrations of lengths 2, 4 and 6 characters are 26 9 (= 234),
676 90 (= 60 840) and 17 576 900 (= 15 818 400) respectively. Since these possibilities are
April 2007 6 CSE/NIT
Basic Combinatorics K. V. Iyer
mutually exclusive and together they exhaust all the possibilities, by the Sum Rule the total
number of possible registrations is 234 + 60 840 + 15 818 400 = 15 879 474.
Example 2.2:
Consider tossing 100 indistinguishable dice. By the Product Rule, it follows that there are 6
100
ways of their falling.
Example 2.3:
A self-dual 2-valued Boolean function is one whose denition remains unchanged if we change all
the 0s to 1s and all the 1s to 0s simultaneously. How many such functions in n-variables exist?
Values of Function
Variables Value
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0
As an example, we consider a Boolean function in 3 variables. The function value is what is
to be assigned in dening the function. As the function is required to be self-dual, it is evident
that an arbitrary assignment (of 0s and 1s) of values cannot be made. The self-duality requires
that changing all 0s to 1s and all 1s to 0s does not change the function denition. Thus, if the
values to the variables are assigned as 0 0 0 and if the function value is 1, then for the assignment
(of variables) 1 1 1 the function value must be the complement of 1 as shown in the table. It is
thus easy see that only 2
n1
independent assignments to the function value can be made. Thus,
the total number of self-dual 2-valued Boolean functions is 2
2
(n1)
.
April 2007 7 CSE/NIT
Basic Combinatorics K. V. Iyer
3 Combinations and Permutations
In obtaining combinations of various objects the general idea is one of selection or grouping.
However, in obtaining permutations of objects the idea is to arrange the objects in some order.
Consider the ve given objects, a, a, a, b, c abbreviated as 3.a, 1.b, 1.c. The adjectives 3, 1,
1 denoting the multiplicities of the objects are referred to as the repetition numbers of the objects.
Ignoring order, the four 3-combinations are: a a a, a a b, a a c and a b c. Taking order into account,
there are thirteen 3-permutations: a a a, a a b, a b a, b a a, a a c, a c a, c a a, a b c, a c b, b a c, b c a,
c a b and c b a.
In allowing unlimited repetitions of objects, we denote the repetition number by . Consider
the 3-combinations possible from .a, .b, .c, .d. There are 20 of them. On the other hand,
there are 4
3
or 64 3-permutations. We use the following notations.
P(n, r) = the number of r permutations of n distinct elements without repetitions.
C(n, r) = the number of r combinations of n distinct elements without repetitions. The modern
notation for this is
_
n
r
_
which is to be read as n choose r .
The following are basic results: P(n, r) =
n!
(nr)!
and C(n, r) =
n!
r!(nr)!
where n! (read as
n-factorial) is the product 1 2 3 n.
3.1 Stirlings Formula
A useful approximation to the value of n! for large values of n was given by James Stirling in
1730. This formula says that when n is large, n! can be approximated by, S
n
=
_
(2n) (n/e)
n
That is, lim
n
n!/S
n
= 1. The following table gives the values of n! and the corresponding S
n
for the indicated n also indicates the percentage error in S
n
.
For standard generalizations of n! see [?].
The following two examples are variations of permutations:
Example 3.1:
Given n objects it is required to arrange them in a circle. In how many ways is this possible?
Let the objects be 1, 2, . . . , n. Keeping 1 xed, it is possible to obtain (n 1)! dierent
arrangements of the remaining objects. For any arrangement it is possible to shift the position of
April 2007 8 CSE/NIT
Basic Combinatorics K. V. Iyer
Table 1: S
n
for the indicated n and percentage error in S
n
n n! S
n
Percentage
error
8 40 320 39 902 1.0357
9 362 880 359 537 0.9213
10 3 628 800 3 598 696 0.8296
11 39 916 800 39 615 625 0.7545
12 479 001 600 475 687 486 0.6919
13 6 227 020 800 6 187 239 475 0.6389
the object 1 while simultaneously shifting (rotating) all the other objects. Thus, the total number
of arrangements is just (n 1)!.
Example 3.2:
Enumerating r-permutations of n objects with unlimited repetitions is easy. We consider r boxes,
each to be lled by one of n possibilities. Thus the answer is U(n, r) = n
r
.
It is easy to see that C(n, r) can also be expressed as n(n 1)(n 2) (n r + 1)/r!
The numerator is often denoted by [n]
r
which is a polynomial in n of degree r. Thus we can
write, [n]
r
= s
o
r
+s
1
r
n +s
2
r
n
2
+ +s
r
r
n
r
.
By denition, the coecients s
k
r
are the Stirling Numbers of the rst kind. These numbers
can be calculated from the following formulas:
s
0
r
= 0, s
r
r
= 1
s
k
r+1
= s
k1
r
rs
k
r
(1)
Proof. By denition, [x]
r+1
= [x
r
](x r). Again by denition, we have from the above equality,
+s
k
r+1
x
k
+ = ( +s
k1
r
x
k1
+s
k
r
x
k
+ )(xr) Equating the coecients of x
k
on both the
sides above, gives the required recurrence. From the above relations we can build the following
April 2007 9 CSE/NIT
Basic Combinatorics K. V. Iyer
table:
s
k
r
k = 0 1 2 3 4
r = 1 0 1 0 0 0
2 0 -1 1 0 0
3 0 2 -3 1 0
4 0 -6 11 -6 1
4 Examples in combinatorial reasoning
Clever reasoning forms a key part in most of the combinatorial problems. We illustrate this with
some typical examples.
Example 4.1:
Show that C(n, r) = C(n, n r).
The left hand side of the equality denotes the number of ways of choosing r objects from n
objects. Each such choice leaves out (nr) objects. This is exactly equivalent to choosing (nr)
objects, leaving out r objects, which is the right hand side.
Example 4.2:
Show that C(n, r) = C(n 1, r 1) +C(n 1, r).
The left hand side is the number of ways of selecting r objects from out of n objects. To do
this, we proceed in a dierent manner. We mark one of the n objects as X. In the selected r
objects, (a) either X is included or (b) X is excluded. The two cases (a) and (b) are mutually
exclusive and totally exhaustive. Case (a) is equivalent to selecting (r 1) objects from (n 1)
April 2007 10 CSE/NIT
Basic Combinatorics K. V. Iyer
objects while case (b) is equivalent to selecting r objects from (n 1) objects.
Example 4.3:
There are a roads from city A to city B, b roads from city B to city C, c roads from city C to
city D, e roads from city A to city C, d roads from city B to city D and f roads from city A to
city D. In how many number of ways one can travel from city A to city D and come back to city
A while visiting at least one of city B and/or city C at least once?
Starting from the city A, the dierent routes leading to city D are shown in the following
tree diagram. It follows that the total number of ways of going to city D from city A is
(abc + ad + ec + f). The tree diagram also suggests (from the leaves to the root) the number
of ways of going from city D to city A is (abc + ad + ec + f). Therefore, the total number of
ways of going from city A to city D and back is (abc + ad + ec + f)
2
. The number of ways of
directly going from city A to city D and back to city A directly is f
2
. Hence the number of
ways of going from city A to city D and back while visiting city B and/or city C at least once is
(abc +ad +ec +f)
2
f
2
.
Example 4.4:
Show that P(n, r) = r P(n 1, r 1) +P(n 1, r).
The left hand side is the number of ways of arranging r objects from out of n objects. This
can be done in the following way. Among the r objects, we mark one object as X. The selected
arrangement either includes X or does not include X. In the former case, we rst select (r 1)
objects from among (n 1) objects and then introduce X in any of the r positions. This gives
the rst term on the right hand side. In the latter case, we simply select r objects from out of
(n 1) objects excluding X. This gives the second term on the right hand side.
Example 4.5:
April 2007 11 CSE/NIT
Basic Combinatorics K. V. Iyer
Count the number of simple undirected graphs with a given set V of n vertices.
Obviously, V contains C(n, 2) = n(n 1)/2 unordered pairs of vertices. We may include or
exclude each pair as an edge in forming a graph with vertex set V . Therefore, there are 2
C(n,2)
simple graphs with vertex set V .
In the above counting, we have not considered isomorphism (see Chapter ??). Thus, although
there are 64 simple graphs having four vertices, there are only eleven of them distinct up to
isomorphism.
Example 4.6:
Let S be a set of 2n distinct objects. A pairing of S is a partition of S into 2-element subsets;
that is, a collection of pairwise disjoint 2-element subsets whose union is S. How many dierent
pairings of S are there?
Method 1: We pick an element say x from S. The number of ways to select xs partner, say
y, is (2n 1). (Now x, y forms a 2-element subset). Consider now the (2n 2) elements in
S x, y. We pick any element say u from S x, y. The number of ways to select us partner,
say v, is (2n3). Thus, the total number of ways of picking x, y and u, v is (2n1)(2n3).
Extending the argument in a similar way and applying the product rule, the total number of ways
of partitioning S into 2-element subsets is given by,
(2n 1) (2n 3) 5 3 1.
Method 2: Consider the n 2-element subsets as n boxes numbered as 1, 2, . . . , n.We form a
2-element subset of S and assign it to box 1. There are C(2n, 2) ways of doing this. Next, we
form a 2-element subset from the remaining (2n 2) elements and assign it to box 2. This can
be done in C(2n2, 2) ways. It is easy to see that the total number of ways to form the dierent
2-element subsets of S is
C(2n, 2) C(2n 2, 2) C(2n 4, 2) C(4, 2) C(2, 2).
April 2007 12 CSE/NIT
Basic Combinatorics K. V. Iyer
However, in the above, we have considered the ordering of the various 2-element subsets also.
Since the ordering is immaterial, the number of ways of partitioning S into 2-element subsets is
1
n!
[C(2n, 2) C(2n 2, 2) C(2n 4, 2) C(4, 2) C(2, 2)]
This expression is the same as the one obtained in the method 1 above.
Example 4.7:
Let S = 1, 2, . . . , (n + 1) where n 2 and let T = (x, y, z) S
3
[x < z and y < z. Show by
counting [T[ in two dierent ways that,

1kn
k
2
= C(n + 1, 2) + 2C(n + 1, 3) . (2)
We rst show that the number on the left-hand side of 2 is [T[: In selecting (x, y, z) we rst
x z = 2. We then have ordered 3-tuples of the form (, , z). The number of ways of lling the
blanks is 1 1 as z is greater than both x and y. Next we x z = 3 to get ordered 3-tuples of the
form (, , z). As both 2 and 1 are less than the xed z, the number of ways of lling the blanks
is 2 2 (whence we get the four ordered 3-tuples (1, 1, 3), (1, 2, 3), (2, 1, 3) and (2, 2, 3) ). The
argument can be extended by xing z = 3, 4, . . . , n. Thus the total number of dierent ordered
3-tuples of the required type is simply 1 1 + 2 2 + + n n = [T[. We next show that the
number on the right-hand side of 2) also represents [T[: We consider two mutually exclusive and
totally exhaustive cases, namely x = y and x ,= y in the 3-tuples of interest. For the rst case,
we select only 2 integers from S, take the larger to be z and the smaller to be both x as well as y.
This can be done in C(n + 1, 2) ways. For the second case, we select 3 integers, take the largest
to be z and assign the remaining two to be x and y in two possible ways (note that each selection
will produce two ordered 3-tuples). The total number of ordered 3-tuples that are possible in this
way is 2C(n + 1, 3). Hence the number of elements in [T[ is C(n + 1, 2) + 2.C(n + 1, 3).
Example 4.8:
A sequence of (mn + 1) distinct integers u
1
, u
2
, . . . , u
mn+1
is given. Show that the sequence
contains either a decreasing subsequence of length greater than m or an increasing subsequence
April 2007 13 CSE/NIT
Basic Combinatorics K. V. Iyer
of length greater than n (this result is due to P. Erdos and G. Szekeres (1935)).
We present the proof as in [?]. Let l
i
() be the length of the longest decreasing subsequence
with the rst term u
i
() and let l
i
(+) be the length of the longest increasing subsequence with
the rst term u
i
(+).
Assume that the result is false. Then u
i
(l
i
(), l
i
(+)) denes a mapping of u
1
, u
2
, . . . , u
mn+1

into the Cartesian product 1, 2, . . . , m 1, 2, . . . , n. This mapping is injective since if i < j,


u
i
> u
j
l
i
() > l
j
() (l
i
(), l
i
(+)) ,= (l
j
(), l
j
(+))
u
i
< u
j
l
i
(+) > l
j
(+) (l
i
(), l
i
(+)) ,= (l
j
(), l
j
(+))
Hence, [u
1
, u
2
, . . . , u
mn+1
[ [1, 2, . . . , m 1, 2, . . . , n[ and therefore mn+1 mn which is
impossible.
(now you should appreciate the next section)
5 The Pigeon-Hole Principle
One deceptively simple counting principle that is useful in many situations is the Pigeon-Hole
Principle. This principle is attributed to Johann Peter Dirichlet in the year 1834 although he
apparently used the German term Schubfachprinzip. The French term is le principe de tiroirs de
Dirichlet which can be translated as the principle of the drawers of Dirichlet.
The Pigeon-Hole Principle: If n objects are put into m boxes and n > m (m and n are positive
integers) then at least one box contains two or more objects.
A stronger form: If n objects are put into m boxes and n > m, then some box must contain at
least [n/m] objects.
Another form: Let k and n be the two positive integers. If at least kn+1 objects are distributed
among n boxes then one of the boxes must contain at least k + 1 objects.
We now illustrate this principle with some examples.
Example 5.1:
Show that, among a group of 7 people there must be at least four of the same sex.
April 2007 14 CSE/NIT
Basic Combinatorics K. V. Iyer
We treat the 7 people as 7 objects. We create 2 boxesone (say, box1) for the objects
corresponding to the females and one (say, box2) for the objects corresponding to the males.
Thus, the 7(= 3 2 +1) objects are put into two boxes. Hence, by the Pigeon-Hole principle there
must be at least 4 objects in one box. In other words, there must be at least four people of the
same sex.
Example 5.2:
Given any ve points, chosen within a square of side with length 2 units, prove there must be two
points which are at most

2 units apart.
Subdivide the square into four small squares each with side of length 1 unit. By the pigeon-
hole principle at least two of the chosen points must be in (or on the boundary) one small square.
But then the distance between these two points cannot exceed the diagonal length,

2 of the
small square.
Example 5.3:
Let A be a set of m positive integers. Show that there exists a nonempty subset B of A such that
the sum

xB
is divisible by m.
We make use of the congruence relation. By a b ( mod m), we mean m divides (a b). A
basic property we will use, is that if a r ( mod m) and b r ( mod m), then a b ( mod m).
Let A = a
1
, a
2
, . . . , a
n
. Consider the following m subsets of A and the sum of their respective
April 2007 15 CSE/NIT
Basic Combinatorics K. V. Iyer
elements:
Set A
1
= a
1
sum of the elements is a
1
Set A
2
= a
1
, a
2
sum of the elements is a
1
+a
2
Set A
3
= a
1
, a
2
, a
3
sum of the elements is a
1
+a
2
+a
3
. . . . . . . . . . . . . . .
Set A
m
= a
1
, a
2
, ..., a
m
sum of the elements is a
1
+a
2
+ +a
m
.
If any of the sums is exactly divisible by m, then the corresponding set is the required subset B.
Therefore, we will assume that none of the above sums is divisible by m. We thus have,
a
1
r
1
( mod m)
a
1
+a
2
r
2
( mod m)
a
1
+a
2
+a
3
r
3
( mod m)
a
1
+a
2
+ +a
m
r
m
( mod m)
where each r
i
(1 i m) is in 1, 2, . . . , (m1). Now, we consider (m1) boxes numbered 1
through (m1) and we distribute the integers r
1
through r
m
to these boxes so that r
i
goes into
box i if r
1
= i . By the Pigeon-Hole principle there must be one box containing an r
i
and an r
j
both of which must be the same, say r. That is, we must have,
a
1
+a
2
+ +a
i
r ( mod m)
and a
1
+a
2
+ +a
j
r ( mod m),
where j > i without loss of generality.
Therefore, m divides the dierence (a
1
+ a
2
+ + a
j
) (a
1
+ a
2
+ + a
i
). Accordingly,
A
j
A
1
is the required subset B.
6 More Enumerations
We now consider the interesting case of enumerating combinations with unlimited repetitions:
April 2007 16 CSE/NIT
Basic Combinatorics K. V. Iyer
Let us consider the distinct objects to be a
1
, a
2
, a
3
, . . . , a
n
. We are interested in selecting
r-combinations from a
1
, a
2
, a
3
, . . . , a
n
.
Any r-combination will be of the form x
1
a
1
, x
2
a
2
, . . . , x
n
a
n
where the x
1
, x
2
, . . . , x
n
are the repitition numbers, each being a non-negative integer and they add up to r. Thus the
number of r-combinations of a
1
, a
2
, a
3
, . . . , a
n
is equal to the number of solutions
of x
1
+x
2
+x
3
+ +x
n
= r.
For each x
i
we put a bin and assign x
i
balls to that bin; the number of balls will add up to r.
Thus the number of solutions to the above equation is equal to the number of ways of placing r
indistinguishable balls in n bins numbered 1 through n. We now make the following observation.
Consider 10 objects and consider the 7-combinations from them. One solution is: (3 0 0 2 0 0 0 2 0 0).
Corresponding to this (distribution of balls in bins) we can form a unique binary number as
follows: rst we separate the integers by a 1 (imagine this as a vertical bar). Then we ignore
the zeros and put (appropriate number of) zeros in the place of non-zero integers. For the above
example, we get, 000 1 1 1 00 1 1 1 1 00 1 1 .
Generalizing this we can say that the number of ways of placing r indistinguishable balls into
n numbered bins is equal to the number of binary numbers with (n 1) 1s and r 0s. Counting
such binary numbers is easy: we have (n 1 +r) positions and we have to choose r positions to
be occupied by the 0s ( the remaining (n 1) positions get lled by 1s ). This can be done in
C(n 1 +r, r) ways. We can now state the result:
Let V (n, r) be the number of r-combinations of n distinct objects with unlimited repitions.
We have, V (n, r) = C(n 1 +r, r) = C(n 1 +r, n 1).
Example 6.1:
The number of integral solutions of, x
1
+ x
2
+ + x
n
= r, x
i
> 0, for all admissible values of i
is equal to the number of ways of distributing r similar balls into n numbered bins with at least
one ball in each bin. This is equal to C(n 1 + (r n), r n) = C(r 1, r n).
April 2007 17 CSE/NIT
Basic Combinatorics K. V. Iyer
6.1 Enumerating permutations with constrained repetitions
We begin with an illustrative example. Consider the problem of obtaining the 10-permutations
of 3 a, 4 b, 2 c, 1 d. Let x be the number of such permutations. If the 3 as are replaced by
a
1
, a
2
, a
3
it is easy to see that we will get 3!x permutations. Further if the 4bs are replaced by
b
1
, b
2
, b
3
, b
4
then we will get (4!)(3!)x permutations. In addition, if we replace the 2cs by c
1
, c
2
we will get (2!)(4!)(3!)x permutations. In the process we have generated the set a
1
, a
2
, a
3
, b
1
,
b
2
, b
3
, b
4
, c
1
, c
2
, d the elements of which can be permuted in 10! ways. Therefore,
(2!)(4!)(3!)x = 10! and hence, x = 10!/(2!)(4!)(3!).
We now generalize the above example.
Let q
1
, q
2
, . . . , q
t
be nonnegative integers such that n = q
1
+ q
2
+ . . . + q
t
. Also let a
1
, a
2
,
. . . , a
t
be t distinct objects. Let P(n; q
1
, q
2
, . . . , q
t
) denote the number of n-permutations of the
n-combination of q
1
a
1
, q
2
a
2
, . . . , q
t
a
t
. By an argument similar to the above example we
have
P(n; q
1
, q
2
, . . . , q
t
) = n!/(q
1
! q
2
! . . . q
t
!) =
C(n, q
1
)C(n q
1
, q
2
)C(n q
1
q
2
, q
3
) . . . C(n q
1
q
2
. . . q
t1
, q
t
)
By substituting the formula for each term in the product, the last expression can be simplied to
the previous expression.
7 Ordered and Unordered Partitions
Let S be a set with n distinct elements and let t be a positive integer. A t-part partition of the
set S is a set A
1
, A
2
, . . . , A
t
of t subsets of S namely, A
1
, A
2
, . . . , A
t
such that
S = A
1
A
2
A
t
,
and A
i
A
j
= , for i ,= j.
This refers to unordered partition.
An ordered partition of S is rstly, a partition of S; secondly there is a specied order on
the subsets. For example, the ordered partitions of S = a, b, c, d of the type 1, 1, 2 are given
April 2007 18 CSE/NIT
Basic Combinatorics K. V. Iyer
below:
(a, b, c, d) (b, a, c, d) (a, c, b, d) (c, a, b, d)
(a, d, b, c) (d, a, b, c) (b, c, a, d) (c, b, a, d)
(b, d, a, c) (d, b, a, c) (c, d, a, b) (d, c, a, b)
Here, our concern is in the number of such partitions rather than the actual list itself.
7.1 Enumerating the ordered partitions of a set
The number of ordered partitions of a set S of the type (q
1
, q
2
, . . . , q
t
) , where [S[ = n, is
P(n; q
1
, q
2
, . . . , q
t
) = n!/(q
1
! q
2
! q
t
!)
We see this by choosing the q
1
elements to occupy the rst subset in C(n, q
1
) ways; the q
2
elements
for the second subset in C(n q
1
, q
2
) ways etc. Thus, the number of ordered partitions of the
type (q
1
, q
2
, . . . , q
t
) is
C(n, q
1
)C(n q
1
, q
2
)C(n q
1
q
2
, q
3
) . . . C(n q
1
q
2
. . . q
t1
, q
t
)
which is equal to n!/(q
1
! q
2
! q
t
!).
Example 7.1:
In the game of bridge, the four players N, E, S and W are seated in a specied order and are
each dealt with a hand of 13 cards. In how many ways can the 52 cards be dealt to the four
players?
We see that the order counts. Therefore, the number of ways is 52!/(13!)
4
.
Example 7.2:
To show that (n
2
)!/(n!)
n
is an integer.
Consider a set of n
2
elements. Partition this set into n-part partitions. Then the number of
ordered n-part partitions is (n
2
)!/(n!)
n
which has to be an integer.
April 2007 19 CSE/NIT
Basic Combinatorics K. V. Iyer
We can also consider partitioning a set of objects into dierent classes. For example, consider
the four objects a, b, c, d. We can partition the set a, b, c, d into two classes: one class containing
two subsets with one and three elements and another class containing two subsets each with two
elements (these are the only possible classes). The partioning gives the following:
(a, b, c, d) , (b, a, c, d) , (c, a, b, d) , (d, a, b, c) ,
(a, b, c, d) , (a, c, b, d) , (a, d, b, c) .
The number of partitions of a set of n objects into m classes, where n m, is denoted by S
m
n
which is called the Stirling Number of the second kind. It is also the number of distinct ways of
arranging a set of n distinct objects into a collection of m identical boxes, not allowing any box
to be empty ( if empty boxes were permitted, then the number would be S
1
n
+S
2
n
+. . . +S
m
n
). It
easily follows that,
S
1
n
= S
n
n
= 1.
Also, S
k
n+1
= S
k1
n
+kS
k
n
, 1 < k < n
Proof. Consider the partitions of (n+1) objects into k classes. We have the following two mutually
exclusive and totally exhaustive cases:
1. The (n+1)
th
object is the sole member of a class: In this case, we simply form the partitions
of the remaining n objects into k1 classes and attach the class containing the sole member.
The number of partitions thus formed is S
k1
n
.
2. The (n + 1)
th
object is not the sole member of any class: In this case, we rst form the
partitions of the remaining n objects into k classes. This gives S
k
n
partitions. In each such
partition we then add the (n+1)
th
object to one of the k classes. We thus get kS
k
n
partitions
of the required type.
From (i) and (ii) above, the result follows.
April 2007 20 CSE/NIT
Basic Combinatorics K. V. Iyer
The interpretation of S
m
n
as the number of partitions of 1, . . . , n into exactly m classes also
yields another recurrence. If we remove the class (say c) containing n and if there are r elements
in the class c then we get a partition of (n r) elements into (m1) classes. The class c can be
chosen in C(n 1, r 1) possible ways. Hence,
S
m
n
=
n

r=1
C(n 1, r 1)S
m1
nr
.
We can use the above relations to build the following table:
S
m
n
m = 1 2 3 4 5 6 7
n = 1 1 0 0 0 0 0 0
2 1 1 0 0 0 0 0
3 1 3 1 0 0 0 0
4 1 7 6 1 0 0 0
5 1 15 25 10 1 0 0
6 1 31 90 65 15 1 0
7 1 63 301 350 140 21 1
8 Combinatorial Identities
There are many interesting combinatorial identities. Some of these identities are suggested by
the Pascals Triangle shown in Fig. 1. Pascals triangle is constructed by rst writing down three
1s in the form of a triangle (this corresponds to the rst two rows in the gure). Any number
(other than the 1s at the ends) in any other row is obtained by summing up the two numbers
in the previous row that are positioned immediately before and after. The 1s at the ends of any
row are simply carried over. We consider below, some well-known combinatorial identities. The
identities 2 through 5 can be seen to appear in the Pascals triangle.
Newtons Identity
C(n, r)C(r, k) = C(n, k)C(n k, r k), for integers n r k 0.
The left-hand side consists of selecting two sets: rst a set A of r objects and then a set B
of k objects from the set A. For example, it is the number of ways of selecting a committee of r
people out of a set of n people and then choosing a subcommittee of k people. The right-hand
side can be viewed as selecting the k subcommittee members in the rst place and then adding
(r k) people, to form the committee, from the remaining (n k) people.
A special case: C(n, r)r = nC(n 1, r 1).
April 2007 21 CSE/NIT
Basic Combinatorics K. V. Iyer
C(0, 0) = 1
C(1, 0) = 1 C(1, 1) = 1
C(2, 0) = 1 C(2, 1) = 2 C(2, 2) = 1
C(3, 0) = 1 C(3, 1) = 3 C(3, 2) = 3 C(3, 3) = 1
C(4, 0) = 1 C(4, 1) = 4 C(4, 2) = 6 C(4, 3) = 4 C(4, 4) = 1
Figure 1:
Pascals Identity: C(n, r) = C(n 1, r) +C(n 1, r 1).
This is attributed to M. Stifel (14861567) and to Blaise Pascal (16231662).
Diagonal Summation:
C(n, 0) +C(n + 1, 1) +C(n + 2, 2) + +C(n +r, r) = C(n +r + 1, r).
The right-hand side is equal to the number of ways to distribute r indistinguishable balls into
(n + 2) numbered boxes. But, the balls may be distributed as follows: x a value for k where
0 k r; for each k distribute the k balls in the rst (n + 1) boxes and then the remainder in
the last box. This can be done in

k=0,1,...,r
C(n +k, k) ways.
Row Summation
C(n, 0) +C(n, 1) +. . . +C(n, r) + +C(n, n) = 2
n
.
Consider nding the number of subsets of a set with n elements. We take n bins (one for
each element). We indicate the picking (respectively, not picking) of an element by putting a 1
(respectively a 0) in the corresponding bin. It is thus easy to see that the total number of possible
subsets is equal to the total number of lling up of the bins (with a 1 or with a 0). This is equal
to 2
n
, the right-hand side of the above equality. Now, the various possible subsets can also be
counted as the the number of subsets with 0 elements, the number of subsets with 1 elements and
April 2007 22 CSE/NIT
Basic Combinatorics K. V. Iyer
so on. This way of enumeration leads to the expression on the left-hand side (the result follows
from binomial theorem).
Row Square Summation
[C(n, 0)]
2
+ [C(n, 1)]
2
+ + [C(n, r)]
2
+ + [C(n, n)]
2
= C(2n, n)
Let S be a set with 2n elements. The right-hand side above counts the number of n-
combinations of n. Now, partition S into two subsets A and B, each with n elements. Then, an
n-combination of S is a union of an r-combination of A and an (n r)-combination of B, for
r = 0, 1, . . . , n. For any r, there are C(n, r)r-combinations of A and C(n, nr)(nr)-combinations
of B. Thus, by the Product Rule there are C(n, r)C(n, n r)n-combinations obtained by tak-
ing r elements from A and (n r) elements from B. Since C(n, n r) = C(n, r). we have
C(n, r)C(n, n r) = [C(n, r)]
2
for each r. Then the Sum Rule gives the left-hand side.
9 The Binomial and the Multinomial Theorems
Theorem 9.1:
Let n be a positive integer. Then all elements x and y belonging to a commutative ring with unit
element with the usual operations + and ,
(x +y)
n
= C(n, 0)x
n
+C(n, 1)x
n1
y +C(n, 2)x
n2
y
2
+ +C(n, r)x
nr
y
r
+ +C(n, n)y
n
Note: For the denition of a commutative ring, see ??. For the present, it is enough to think x
and y as real numbers.
Proof. The inductive proof is well-known. Below, we present the combinatorial proof. We write
the left-hand side explicitly as consisting of n factors:
(x +y)(x +y) (x +y)
We select an x or a y from each factor (x + y). This gives terms of the form x
nr
y
r
for each
April 2007 23 CSE/NIT
Basic Combinatorics K. V. Iyer
r = 0, 1, . . . , n. We collect all such terms with similar exponents on x and y and sum them up.
This sum is then the coecient of the term of the form x
nr
y
r
in the expansion of (x +y)
n
. For
any given r, to get the term x
nr
y
r
we select r of the ys from the n factors (x gets chosen from
the remaining n r factors). This can be done in C(n, r) ways. This then is the coecient of
x
nr
y
r
as required by the theorem.
The binomial coecients (of the type C(n, r)) appearing above occur in the Pascals triangle.
For a xed n, we can obtain the ratio of the (k +1)
st
bionomial coecient of order n to the k
th
:
C(n, k + 1)/C(n, k) = (n k)/(k + 1).
This ratio is larger than 1 if k < (n 1)/2 and is less than 1 if k > (n 1)/2. Therefore,
we can infer that the biggest binomial coecient must occur in the middle. We use Stirlings
approximation to estimate how big the binomial coecients are:
C(n, n/2) =
n!
(n/2)!
=
(n/e)
n
_
(2n)
(n/2e)
n/2
_
(n)
2
= 2
n
_
(2/n)
Corollary 9.2:
Using binomial theorem the expansions for (1 +x)
n
and (1 x)
n
are immediate.
If we set x = 1 and y = 1 in the Binomial Theorem, we get
C(n, 0) C(n, 1) +C(n, 2) + (1)
n
C(n, n) = 0.
We can write this as:
C(n, 0) +C(n, 2) +C(n, 4) + = C(n, 1) +C(n, 3) +C(n, 5) + = S
Let S denote the common sum. Then, by previous identity (see row summation), adding the two
series, we get 2S = 2
n
or S = 2
n1
. The combinatorial interpretation is easy. If S is a set with n
elements, then the number of subsets of S with an even number of elements is equal to number
of subsets of S with an odd number of elements and each of these is equal to 2
n1
.
Example 9.3:
April 2007 24 CSE/NIT
Basic Combinatorics K. V. Iyer
To show that: 1 C(n, 1) + 2 C(n, 2) + 3 C(n, 3) + + n C(n, n) = n2
n1
, for each positive
integer n.
We use the Newtons Identity, rC(n, r) = nC(n 1, r 1) to replace each term on left-hand
side; then the expression on the left reduces to
n[C(n 1, 0) + +C(n 1, n 1)] = n2
n1
giving the expression on the right.
The Multinomial Theorem: This concerns with the expansion of multinomials of the form
(x
1
+x
2
+. . . +x
t
)
n
.
Here, the role of the binomial coecients gets replaced by the multinomial coecients
P(n; q
1
, q
2
, . . . , q
t
) =
n!
q
1
!q
2
! q
t
!
where q
i
s are non-negative integers and

q
i
= n. (recall that the multinomial coecients
enumerate the ordered partitions of a set of n elements of the type (q
1
, q
2
, . . . , q
t
)).
Example 9.4:
By long multiplication we can get, (x
1
+ x
2
+ x
3
)
3
= x
3
1
+ x
3
2
+ x
3
3
+ 3x
2
1
x
2
+ 3x
2
1
x
3
+ 3x
1
x
2
2
+ 3x
1
x
2
3
+ 3x
2
x
2
3
+ 3x
2
2
x
3
+ 6x
1
x
2
x
3
.
To get the coecient of, say, x
2
x
2
3
we choose x
2
from one of the factors and x
3
from the
remaining two. This can be done in C(3, 1) C(2, 2) = 3 ways; therefore the required coecient
should be 3.
Example 9.5:
Find the coecient of x
4
1
x
5
2
x
6
3
x
3
4
in (x
1
+x
2
+x
3
+x
4
)
18
.
The product will occur as often as, x
1
can be chosen from 4 out of the 18 factors, x
2
from 5
out of the remaining 14 factors, x
3
from 6 out of the remaining 9 factors and x
4
from out of the
April 2007 25 CSE/NIT
Basic Combinatorics K. V. Iyer
last 3 factors. Therefore the coecient of x
4
1
x
5
2
x
6
3
x
3
4
must be
C(18, 4) C(14, 5) C(9, 6) C(3, 3) = 18!/4!5!6!3!.
Generalization of the above yields the following theorem:
Theorem 9.6 (The Multinomial Theorem):
Let n be a positive integer. Then for all x
1
, x
2
, . . . ,x
t
we have,
(x
1
+x
2
+ +x
t
)
n
=

P(n; q
1
, q
2
, ..., q
t
)x
q1
1
x
q2
2
x
qt
t
where the summation extends over all sets of non-negative integers q
1
, q
2
, . . . , q
t
with q
1
+ q
2
+
+q
t
= n.
To count the number of terms in the above expansion, we note that each term of the form x
q1
1
, x
q2
2
, . . . , x
qt
t
corresponds to a selection of n objects with repetitions from t distinct types. There
are C(n +t 1, n) ways of doing this. This then is the number of terms in the above expansion.
Example 9.7:
In (x
1
+ x
2
+ x
3
+ x
4
+x
5
)
10
, the coecient of x
2
1
x
3
x
3
4
x
4
5
is
P(10; 2, 0, 1, 3, 4) = 10!/2!0!1!3!4! = 12, 600.
There are C(10 + 5 1, 10) = C(14, 10) = 1001 terms in the above multinomial expansion.
Corollary 9.8:
In the multinomial theorem if we let x
1
= x
2
= = x
t
= 1, then for any positive interger t,
we have t
n
=

P(n; q
1
, q
2
, . . . , q
t
), where the summation extends over all sets of non-negative
integers q
1
, q
2
, . . . , q
t
with

q
i
= n.
April 2007 26 CSE/NIT
Basic Combinatorics K. V. Iyer
10 Principle of Inclusion-Exclusion
The Sum Rule stated earlier (see 1.2 ) applies only to disjoint sets. A generalization is the
Inclusion- Exclusion principle which applies to non-disjoints sets as well.
We rst consider the case of two sets. If A and B are nite subsets of some universe U, then
[A B[ = [A[ +[B[ [A B[
By the Sum Rule
[A B[ = [A B

[ +[A B[ +[A

B[ (3)
Also, we have
[A[ = [A B

[ +[A B[
[B[ = [A

B[ +[A B[, and


[A[ +[B[ = [A B

[ +[A

B[ + 2[A B[ (4)
(5)
From (3) and (4), we get
[A B[ = [A[ +[B[ [A B[.
Example 10.1:
From a group of ten professors, in how many ways can a committee of ve members can be formed
so that at least one of professor A or professor B is included?
Let A
1
and A
2
be the sets of committees that include professor A and professor B respectively.
Then the required number is [A
1
A
2
[ . Now,
[A
1
[ = C(9, 4) = 126 = [A
2
[ and [A
1
A
2
[ = C(8, 3) = 56.
Therefore it follows that [A
1
A
2
[ = 126 + 126 56 = 196.
The Inclusion-Exclusion Principle for the case of three sets can be stated as given below:
If A, B and C are three nite sets then
[A B C[ = [A[ +[B[ +[C[ [A B[ [A C[ [B C[ +[A B C[
April 2007 27 CSE/NIT
Basic Combinatorics K. V. Iyer
The result can be obtained easily using Venn diagram.
We now state a more general form of the Inclusion-Exclusion Principle.
Theorem 10.2:
If A
1
, A
2
, . . . , a
n
are nite subsets of a universal set then,
[A
1
A
2
A
n
[ =

[A
i
[

[A
i
A
j
[ +

[A
i
A
j
A
k
[
+(1)
n1
[A
1
A
2
. . . A
n
[ (6)
the second summation on the right-hand side is taken over all the 2-combinations (i, j) of
the integers 1, 2, ..., n; the third summation is taken over all the 3-combinations (i, j, k) of the
integers 1, 2, ..., n and so on. Thus, for n = 4, there are 4 +C(4, 2) +C(4, 3) + 1 = 2
4
1 = 15
terms on the right-hand side. In general there are,
C(n, 1) +C(n, 2) +C(n, 3) + +C(n, n) = 2
n
1
terms on the right-hand side.
(Note: the term C(n, 0) is missing; so the 1 appears on right hand side)
Proof. The proof by induction is boring! Here we give the proof based on combinatorial argu-
ments.
We must show that every element of A
1
A
2
A
n
is counted exactly once in the right
hand side of (6). Suppose that an element x A
1
A
2
A
n
is in exactly m (integer, 1)
of the sets considered on the right-hand side of (6); for deniteness, say
x A
1
, x A
2
, . . . , x A
m
and x / A
m+1
, . . . , x / A
n
.
Then x will be counted in each of the terms [A
i
[, for i = 1, . . . , m; in other words x will be counted
C(m, 1) times in the

[A
i
[ term on right-hand side of (6). Also, x will be counted C(m, 2)
times in the

[A
i
A
j
[ term on right-hand side of (6) since there are C(m, 2) pairs of sets A
i
,
April 2007 28 CSE/NIT
Basic Combinatorics K. V. Iyer
A
j
where x is in both A
i
and A
j
. Likewise x is counted C(m, 3) times in the

[A
i
A
j
A
k
[
term since there are C(m, 3) 3-combinations of A
i
, A
j
and A
k
such that x A
i
, x A
j
and
x A
k
. Continuing in this manner, we see that on the right hand side of (6) x is counted,
C(m, 1) C(m, 2) +C(m, 3) + + (1)
m1
C(m, m)
number of times. Now, we must show that, this last expression is 1. Expanding (m1)
m
by the
Binomial Theorem we get,
0 = C(m, 0) C(m, 1) +C(m, 2) + + (1)
m1
C(m, m).
Using the fact that C(m, 0) = 1 and transposing all other terms to the left-hand side of the above
equation, we get the required relation.
10.1 Eulers -function
If n is a positive integer, by denition, (n) is the number of integers x such that 1 x n and
n and x are relatively prime (note: two positive integers are relatively prime if their gcd is 1).
For example, (30) = 8 because the eight integers 1, 7, 11, 13, 17, 19, 23 and 29 are the only
positive integers less than 30 and relatively prime to 30.
Let A
i
be the subset of U consisting of those integers divisible by p
i
. The integers in U
relatively prime to n are those in none of the subsets A
1
, A
2
, . . . , A
k
. So,
(n) = [A

1
A

2
A

k
[ = [U[ [A
1
A
2
A
k
[
If d divides n, then there are n/d multiples of d in U. Hence,
[A
i
[ = n/p
i
, [A
i
A
j
[ = n/p
i
p
j
, [A
1
A
2
A
k
[ = n/p
1
p
2
. . . p
k
.
Thus by Inclusion-Exclusion Principle,
(n) = n

i
n/p
i
+

1ijk
n/p
i
p
j
+ + (1)
k
(n/p
1
p
2
p
k
).
April 2007 29 CSE/NIT
Basic Combinatorics K. V. Iyer
This is equal to the product n
_
1
1
p
1
__
1
1
p
2
_

_
1
1
p
k
_
.
It turns out that computing (n) is as hard as factoring n. The following is a beautiful identity
involving the Euler -function due to Smith (1875):

(1, 1) (1, 2) . . . (1, n)


(2, 1) (2, 2) . . . (2, n)
.
.
.
.
.
.
.
.
.
.
.
.
(n, 1) (n, 2) (n, n)

= (1)(2) (n)
where (a, b) denotes the gcd of the integers a and b.
10.2 Inclusion-Exclusion Principle and the Sieve of Eratosthenes
The Greek mathematician Eratosthenes who lived in Alexandria in the 3
rd
century B.C. devised
the sieve technique to get all primes between 2 and n. The method starts by writing down all the
integers from 2 to n in the natural order. Then starting with the smallest that is 2, every second
number (these are multiples of 2) is crossed out. Next starting with the smallest (uncrossed)
number, that is 3, every third number (these are multiples of 3) is crossed out. This procedure
is repeated until a stage is reached when no more numbers could be crossed out. The surviving
uncrossed numbers are the required primes.
Book example: Compute how many integers between 1 and 1000 are not divisible by 2, 3, 5
and 7; that is how many integers remain after the rst 4 steps of the sieve method.
Let U be the set of integers x such that 1 x 1000. Let A
1
, A
2
, A
3
, A
4
be the sets of
elements (of U) divisible by 2, 3, 5 and 7 respectively. Then, A
1
A
2
A
3
A
4
is the set of
numbers in U that are divisible by at least one of 2, 3, 5, and 7. Hence the required number is
April 2007 30 CSE/NIT
Basic Combinatorics K. V. Iyer
[(A
1
A
2
A
3
A
4
)

[ . We know that,
[A
1
[ = 1000/2 = 500; [A
2
[ = 1000/3 = 333;
[A
3
[ = 1000/5 = 200; [A
4
[ = 1000/7 = 142;
[A
1
A
2
[ = 1000/6 = 166; [A
1
A
3
[ = 1000/10 = 100;
[A
1
A
4
[ = 1000/14 = 71; [A
2
A
3
[ = 1000/15 = 66;
[A
2
A
4
[ = 1000/21 = 47; [A
3
A
4
[ = 1000/35 = 28;
[A
1
A
2
A
3
[ = 1000/30 = 33; [A
1
A
2
A
4
[ = 1000/42 = 23;
[A
1
A
3
A
4
[ = 1000/70 = 14; [A
2
A
3
A
4
[= 1000/106 = 9;
[A
1
A
2
A
3
A
4
[ = 1000/210 = 4
Then, [A
1
A
2
A
3
A
4
[ =
(500 + 333 + 200 + 142) (166 + 100 + 71 + 66 + 47 + 28) + (33 + 23 + 14 + 9) 4 = 772.
Therefore, [(A
1
A
2
A
3
A
4
)

[ = 1000 772 = 228.


11 Derangements
Derangements are permutations of 1, . . . , n in which none of the n elements appears in its
natural place. Thus, (i
1
, i
2
, . . . , i
n
) is a derangement if i
1
,= 1, i
2
,= 2, . . . , and i
n
,= n.
Let D
n
denote the number of derangements of (1, 2, . . . , n). It follows that D
1
= 0; D
2
= 1,
because (2, 1) is a derangement; D
3
= 2 because (2, 3, 1) and (3, 1, 2) are the only derangements
of (1, 2, 3). We will determine D
n
using the Inclusion-Exclusion principle.
Let U be the set of all n! permutations of 1, 2, . . . , n. For each i, let A
i
be the set of
permutations such that element i is in its correct place; that is, all permutations (b
1
, b
2
, . . . , b
n
)
such that b
i
= i. Evidently, the set of derangements is precisely the set A

1
A

2
A

3
A

n
;
the number of elements in it is D
n
.
Now, the permutations in A
1
are all of the form (1, b
2
, . . . , b
n
) where (b
2
, . . . , b
n
) is a permu-
tation of 2, . . . , n. Thus [A
1
[ = (n 1)!. Similarly it follows thet [A
i
[ = (n 1)!.
Likewise, A
1
A
2
is the set of permutations of the form (1, 2, b
3
, . . . , b
n
), so that [A
1
A
2
[ =
(n2)!. We can similarly argue, [A
i
A
j
[ = (n2)! for all admissible pairs of values of i, j, i ,= j.
April 2007 31 CSE/NIT
Basic Combinatorics K. V. Iyer
For any integer k, where 1 k n, the permutations in A
1
A
2
. . . A
k
are of the form
(1, 2, . . . , k, b
k+1
, . . . , b
n
)
where (b
k+1
, . . . , b
n
) is a permutations of (k + 1, . . . , n). Thus, [A
1
A
2
. . . A
k
[ = (n k)! .
More generally, we have [A
i1
A
i2
. . . A
ik
[ = (n k)! for i
1
, i
2
, . . . , i
k
, a k-combination
of 1, 2, . . . , n. Therefore,
[(A

1
A

2
A

3
A

n
)[ = [U[ [A
1
A
2
. . . A
n
[
= n! C(n, 1)(n 1)! +C(n, 2)(n 2)! +. . . + (1)
n
C(n, n)
= n!
n!
1!
+
n!
2!

n!
3!
+. . . + (1)
n
n!
n!
.
Thus, D
n
= n!
_
1
1
1!
+
1
2!

1
3!
+. . . + (1)
n 1
n!
_
.
We can get a quick approximation to D
n
in terms of the exponential e. We know that,
e
1
= 1 (1/1!) + (1/2!) (1/3!) +...
+ (1)
n
(1/n!) + (1)
n+1
(1/(n + 1)!) +. . .
or e
1
= (D
n
/n!) + (1)
n+1
(1/(n + 1)!) + (1)
n+2
(1/(n + 2)!) +. . .
or [e
1
(D
n
/n!)[ (1/(n + 1)!) + (1/(n + 2)!) +. . .
(1/(n + 1)!)[1 + (1/(n + 2)) + (1/(n + 2)
2
) +. . .]
(1/(n + 1)!)[1/1 (1/(n + 2)]
= (1/(n + 1)!)[1 + 1/(n + 1)]
As n , we know (n+1)! at a faster rate; thus for large values of n, we regard n!/e as a
good approximation to D
n
. For example, D
8
= 14833 and the value of 8!/e is about 14832.89906.
A dierent approach leads to a recurrence relation for D
n
. In considering the derangements of
1, . . . , n, n 2 we can form two mutually exclusive and totally exhaustive cases as follows:
1. The integer 1 is displaced to the k
th
position (1 < k n) and k is displaced to the 1
st
position: In this case, the total number of derangements of is equal to the number of
derangements of the set of n2 numbers 2, 3, . . . , k 1, k +1, ..., n. The required number
is thus D
n2
.
2. The integer 1 is displaced to the k
th
position (1 < k n) but k is displaced to a position
dierent from the 1
st
position: These are precisely the derangements of the set of n 1
April 2007 32 CSE/NIT
Basic Combinatorics K. V. Iyer
numbers k, 2, 3, . . . , k 1, k + 1, ..., n. Clearly, any derangement will displace the integer
k from the 1
st
position. The required number is thus D
n1
.
We note that in the above argument, k can be any one of 2, 3, ..., n; that is, it can take
(n 1) possible values. Thus, we have,
D
n
= (n 1)(D
n1
+D
n2
)
By algebraic manipulations, it can be shown that D
n
nD
n1
= (1)
n
, for n 2. This
recurrence relation when solved with the initial condition gives,
D
n
= n!
n1

i=1
(1)
i+1
(i + 1)!
.
12 Partition Problems
Several interesting combinatorial problems arise in connection with the partioning of integers.
These are collectively referred to as partition problems. We denote as p(n, m), the number of
partitions of an integer n into m parts. We write,
n =
1
+
2
+ +
m
and specify
1

2

m
1
For example the partitions of 2 are 2 and 1 + 1; so p(2, 1) = p(2, 2) = 1. The partitions of 3 are
3, 2 + 2 and 1 + 1 + 1 and so, p(3, 1) = p(3, 2) = p(3, 3) = 1. Similarly the partitions of 4 are 4,
3 + 1, 2 + 2, 2 + 1 + 1 and 1 + 1 + 1 + 1; so p(4, 2) = 2 and p(4, 1) = p(4, 3) = p(4, 4) = 1.
12.1 Recurrence relations p(n, m)
The following recurrence relations can be used to compute p(n, m):
p(n, 1) +p(n, 2) + +p(n, k) = p(n +k, k) (7)
and p(n, 1) = p(n, n) = 1 (8)
Proof. The second formula is obvious by denition. We proceed to prove the rst formula.
Let A be the set of partitions of n having m parts, m k ; each partition in A can be
considered as a k-tuple. Let B be the set partitions of n + k into k parts. Dene a mapping :
April 2007 33 CSE/NIT
Basic Combinatorics K. V. Iyer
Figure 2: Figure 3:
A B by setting,
(
1
,
2
, . . . ,
m
) = (
1
+ 1,
2
+ 1, . . . ,
m
+ 1, 1, 1, . . . , 1)
Since
1
+
2
+ +
m
= n, the sequence on the right side above (equation ***) gives a partition
of n +k into k parts. (Note that if m = k the 1s in the partion of n +k will be absent.)
Clearly the mapping is bijective. Hence,
[A[ = p(n, 1) +p(n, 2) + +p(n, k) = [B[ = p(n +k, k)
The equations (7) and (8) allow us to compute p(n, m)s recursively. For example, if n = 4
and m = 6 the values of p(n, m)s for n 4 and m 6 are given by the following array:
p(n, m) m = 1 2 3 4 5 6
n = 1 1 0 0 0 0 0
2 1 1 0 0 0 0
3 1 1 1 0 0 0
4 1 2 1 1 0 0
5 1 2 2 1 1 0
6 1 3 3 2 1 1
12.2 Ferrer Diagrams
We next illustrate the idea of Ferrer diagram to represent a partition. Consider a partition such
as 5 +3 +2 +2. We represent it diagrammatically as shown in the Fig. 2. The representation as
seen in the diagram has one row for each part; the number of squares in a row is equal to the size
of the part it represents; an upper row has at least as many number of squares as there are in a
lower row; the rows are aligned to the left.
The partition obtained by rendering the columns (of a given partition) as rows is known as the
conjugate partition of a given partition. For example, from the above Ferrer diagram it follows
(by turning the gure by 90
o
clockwise and by taking a mirror reection) that the conjugate
partition of 5 + 3 + 2 + 2 is 4 + 4 + 2 + 1 + 1.
April 2007 34 CSE/NIT
Basic Combinatorics K. V. Iyer
Fact 1.
The number of partitions of n into k parts is equal to the number of partitions of n into parts,
of which the largest is k. It is easy to see that we can establish a bijection between the set of
partitions of n having k as the largest part. This follows from the Ferrer diagram.
Fact 2.
The number of self-conjugate partitions of n is the same as the number of partitions of n with all
parts unequal and odd.
Consider the Ferrer diagram associated with a partition of n with all parts unequal and
odd. We can obtain a new Ferrer diagram by placing the squares of each row in a set-square
arrangement as shown in Fig. 3.
The new Ferrer diagram denes a self-conjugate partition. Similarly, reversing the argument,
each self-conjugate partition corresponds to a unique partition with all parts unequal and odd.
Fact 3.
The number of partitions of n is equal to the number of partitions of 2n which have exactly n
parts.
Any partition of n can have at most n parts. Treat each partition as an n-tuple, (
1
,
2
, . . . ,
n
)
where, in general, for some i all
i+1
to
n
will be 0. Now add 1 to each
j
, 1 j n this
denes a partition of 2n (as we are adding n 1s) where there must be exactly n parts. It is easy
to see that we have a bijection from the set of the original n-tuples to the set of n-tuples formed
as above. Hence the result follows.
13 Solution of Recurrence Relations
Dierent types of recurrence relations (also known as dierence equations) arise in many enumer-
ation problems and in the analysis of algorithms. We illustrate many types of recurrence relations
and the commonly adopted techniques and tricks used to solve them. We also give the general
technique based on generating functions to solve recurrence relations. [?], [?] and [?] provide a
good material for solving recurrence relations.
April 2007 35 CSE/NIT
Basic Combinatorics K. V. Iyer
Example 13.1:
The number D
n
of derangements of the integers (1, 2, . . . , n) as we have seen in section *** satises
the recurrence relation, D
n
nD
n1
= (1)
n
, for n 2 with D
1
= 0. The easiest way to solve
this recurrence relation is to rewrite it as
D
n
n!

D
n1
(n 1)!
=
(1)
n
n!
.
Example 13.2:
The sorting problem asks for an algorithm that takes as input a list or an array of n integers and
that sorts them that is, arranges them in nondecreasing (or nonincreasing) order. One algorithm,
call it procedure Mergesort(n), does this by splitting the given list of n integers into two sublists
of n/2| and n/2| integers, applies the procedure on the sublists to sort them and merges the
sorted sublists (note the recursive formulation). If the time taken by procedure Mergesort(n)
in terms of the number of comparisons is denoted by T(n) then T(n) is known to satisfy the
following recurrence relation:
T(n) = T
__
n
2
_ _
+T
__
n
2
_ _
+n 1, with T(2) = 1
The above method is characteristic of divide-and-conquer algorithms where a main problem
of size n is split it into b (b > 1) subproblems of size say, n/c (c > 1); the subproblems are
solved by further splitting; the splitting stops when the size of the subproblems are small enough
to be solved by a simple technique. A divide-and-conquer algorithm combines the solutions to
the subproblems to yield a solution to the original problem. Thus there is a non-recursive cost
(denoted by the function f(.), necessarily asymptotically positive) associated in splitting and/or
combining (the solutions). Thus we generaly get a recurrence relation of the type,
T(n) = bT(n/c) +f(n).
Solution to the above kind of recurrence using Masters method is well-known.
April 2007 36 CSE/NIT
Basic Combinatorics K. V. Iyer
Example 13.3:
Consider the problem of nding the number of binary sequences of length n which do not contain
two consecutive 1s.
Let w
n
be the number of such sequences. Let u
n
be the number of such sequences whose last
digit is a 1. Also, let v
n
be the number of such sequences whose last digit is a 0. Obviously,
w
n
= u
n
+v
n
.
Consider extending any sequence of the required type from length n1 to length n. We have
the following two possibilities:
1. If a sequence of length n 1 ends with a 1 then, we can append a 0 but not a 1.
2. If a sequence of length n 1 ends with a 0 then, we can append either a 0 or a 1.
It is not dicult to reason that u
n
and v
n
can be counted as given by the following recurrence
relations:
v
n
= v
n1
+u
n1
and u
n
= v
n1
.
These lead to the equations,
v
n
= v
n1
+v
n2
and u
n
= u
n1
+u
n2
which when added give the recurrence relation,
w
n
= w
n1
+w
n2
.
This equation is the same as that for Fibonacci numbers, which can be solved with the initial
conditions w
1
= 2 and w
2
= 3.
Example 13.4:
A circular disk is divided into n sectors. There are p dierent colors (of paints) to color the sectors
so that no two adjacent sectors get the same color. We are interested in the number of ways of
coloring the sectors.
April 2007 37 CSE/NIT
Basic Combinatorics K. V. Iyer
Let u
n
be the number of ways to color the disk in the required manner. This number clearly
depends upon both n and p. We form a recurrence relation in n using the following reasoning as
given in [?]. We construct two mutually exclusive and exhaustive cases:
1. The sectors 1 and 3 are colored dierently. In this case, removing sector 2 gives a disk of
n 1 sectors. Sector 2 can be colored in p 2 ways.
2. The sectors 1 and 3 are of the same color. In this case, removing sector 2 gives a disk of
n 2 sectors as sectors 1 and 3 being of the same color can be fused as one. Sector 2 can
be colored using any of the p 1 colors (i.e., excluding the color of sector 1 or sector 3).
For each coloring of sector 2, we can color the disk of n 2 sectors in u
n2
ways. Thus, we
have the following recurrence relation:
u
n
= (p 2)u
n1
+ (p 1)u
n2
with the initial conditions, u
2
= p(p 1)andu
3
= p(p 1)(p 2).
The solution can be obtained as, u
n
= (p 1)[(p 1)
n1
+ (1)
n
].
13.1 Homogeneous Recurrences
The recurrence relations in the above examples can be solved using the techniques described in
this section. In general, we can consider equations of the form,
a
n
= f(a
n1
, a
n2
, . . . , a
ni
), where n i
Here we have a recurrence with nite history as a
n
depends on a xed number of earlier values.
If a
n
depends on all the previous values then the recurrence is said to have a full history. In
this section, we here consider equations of the form,
c
0
a
n
+c
1
a
n1
+... +c
k
a
nk
= 0. (9)
The above equation is linear as it does not contain terms like a
ni
a
nj
, a
2
ni
and so on; it is
homogeneous as the linear combination of a
ni
is zero; it is with constant coecients because the
c
i
s are constants. For example, the well-known Fibonacci Sequence 0, 1, 1, 2, 3, 5, 8, 13, 21,
April 2007 38 CSE/NIT
Basic Combinatorics K. V. Iyer
34, . . . is dened by the linear homogeneous recurrence, f
n
= f
n1
+f
n2
, when n 2 with the
initial conditions, f
0
= 0 and f
1
= 1.
It is easy to see that if f
n
and g
n
are solutions to (9), then so does a linear combinations of
f
n
and g
n
say pf
n
+ qg
n
, where p and q are constants. To solve (9), we try a
n
= x
n
where x is
an unknown constant. If a
n
= x
n
is used in (9) we should have,
c
0
x
n
+c
1
x
n1
+. . . +c
k
x
nk
= 0.
The solution x = 0 is trivial; otherwise, we must have
p(x) c
o
x
k
+c
1
x
k1
+. . . +c
k
= 0.
The equation p(x) = 0 is known as the characteristic equation which can be solved for x.
Example 13.5:
Consider the Fibonacci Sequence as above. We can write the recurrence relation as
f
n
f
n1
f
n2
= 0. (10)
The characteristic equation is x
2
x 1 = 0. The roots r
1
, r
2
of this equation are given by,
r
1
= (1 +

5)/2 and r
2
= (1

5)/2.
So, the general solution of (10) is, f
n
= c
1
r
n
1
+c
2
r
n
2
.
Using the initial conditions f
0
= 0 and f
1
= 1 we get, c
1
+ c
2
= 0 and c
1
r
1
+ c
2
r
2
= 1 which
give, c
1
= 1/

5 and c
2
= 1/

5.
Thus the n
th
Fibonacci number f
n1
is given by,
f
n1
=
1

5
_
1 +

5
2
_
n1

5
_
1

5
2
_
n1
It is interesting to observe that the solution of the above recurrence which has integer coecients
and integer initial values, involves irrational numbers.
Example 13.6:
Consider the relation,
a
n
6a
n1
+ 11a
n2
6a
n3
= 0, n > 2
April 2007 39 CSE/NIT
Basic Combinatorics K. V. Iyer
with a
0
= 1, a
1
= 3 and a
2
= 5.
From the given equation we directly write its chracteristic equation as,
x
3
6x
2
+ 11x 6 = 0,
that is, (x 1)(x 2)(x 3) = 0.
Thus the roots of the characteristic equation are, 1, 2 and 3 and the solution should be of the
form, a
n
= A1
n
+B2
n
+C3
n
.
Applying the initial conditions, we get,
a
0
= 1 = A+B +C; a
1
= 3 = A+ 2B + 3C; and a
2
= 5 = A+ 4B + 9C
which yield, A = 2, B = 4 and C = 1.
Hence the solution is given by a
n
= 2 + 4.2
n
3
n
.
We next deal with the case when the characteristic equation has multiple roots. Let the
characteristic polynomial p(x) be,
p(x) = c
o
x
k
+c
1
x
k1
+ +c
k
.
Let r be a multiple root occurring two times; that is, (x r)
2
is a factor of p(x). We can write,
p(x) = (x r)
2
q(x), where q(x) is of degree (k 2).
For every n k consider the n
th
degree polynomials,
u
n
(x) = c
0
x
n
+c
1
x
n1
+. . . +c
k
x
nk
and v
n
(x) = c
0
nx
n
+c
1
(n 1)x
n1
+ +c
k
(n k)x
nk
.
We note that, v
n
(x) = xu

n
(x).
April 2007 40 CSE/NIT
Basic Combinatorics K. V. Iyer
Now, u
n
(x) = x
nk
p(x) = x
nk
(x r)
2
q(x) = (x r)
2
[x
nk
q(x)]
So, u

n
(r) = 0, which implies that v
n
(r) = ru

n
(r) = 0, for all n k.
That is, c
0
nr
n
+c
1
(n 1)r
n1
+ +c
k
(n k)r
nk
= 0.
From (9), we conclude a
n
= nr
n
is also a solution to the given recurrence.
More generally, if root r has multiplicity m, then a
n
= r
n
, a
n
= nr
n
, a
n
= n
2
r
n
, . . . ,
a
n
= n
m1
r
n
all are distinct solutions to the recurrence.
Example 13.7:
Consider the recurrence, a
n
11a
n1
+ 39a
n2
45a
n3
= 0, when n > 3 with a
0
= 0, a
1
= 1
and a
2
= 2.
We can write the characteristic equation as
x
3
11x
2
+ 39x 45 = 0,
the roots of which are 3, 3 and 5. Hence, the general solution can be written as
a
n
= (A+Bn)3
n
+C5
n
.
Using the initial conditions, we get a
0
= A + C = 0; a
1
= 3(A + B) + 5C = 1; and a
2
=
9(A+ 2B) + 25C = 2. This gives, A = 1, B = 1 and C = 1.
Hence the required solution is given by,
a
n
= (1 +n)3
n
+ 5
n
.
13.2 Inhomogeneous Equations
Inhomogeneous equations are more dicult to handle and linear combinations of the dierent
solutions may not be a solution. We begin with a simple case.
c
0
a
n
+c
1
a
n1
+ +c
k
a
nk
= b
n
p(n).
April 2007 41 CSE/NIT
Basic Combinatorics K. V. Iyer
Here the left-hand side is same as before; on the right-hand side, b is a constant and p(n) is a
polynomial in n of degree d. The following example is illustrative.
Example 13.8:
Consider the recurrence relation,
a
n
3a
n1
= 5
n
(11)
Multiplying by 5, we get 5a
n
15a
n1
= 5
n+1
Replacing n by n 1, we get 5a
n1
15a
n2
= 5
n
(12)
Subtracting (12) from (11), a
n
8a
n1
+ 15a
n2
= 0 (13)
The corresponding characteristic polynomial is x
2
8x + 15 = (x 3)(x 5) and so we can
write the general solution as,
a
n
= A3
n
+B5
n
(14)
We can observe that 3
n
and 5
n
are not solutions to (11)! The reason is that (11) implies (13),
but (13) does not imply (11) and hence they are not equivalent.
From the original equation we can write a
1
= 3a
0
+ 5, where a
0
is the initial condition.
From (14) we get, A+B = a
0
and 3A+ 5B = a
1
= 3a
0
+ 5.
Therefore, we should have, A = a
0
5/2 and B = 5/2.
Hence, a
n
= [(2a
0
5)3
n
+ 5
n+1
]/2.
13.3 Repertoire Method
The repertoire method (illustrated in [?]) is one technique that works by trial and error and
may be useful in certain cases. Consider for example,
a
n
na
n1
+ (n 2)a
n2
= (2 n),
with the initial condition a
1
= 0 and a
2
= 1. We relax the above recurrence by writing a
general function, say f(n) on the right-hand side of the above equation. Thus, we consider the
April 2007 42 CSE/NIT
Basic Combinatorics K. V. Iyer
equation,
a
n
na
n1
+ (n 2)a
n2
= f(n).
We now try various possible candidate solutions for a
n
, evaluate the left-hand side above and
check to see if it yields the required value for f(n) the required f(n) should be (2 n). We
tabulate the work as follows:
Row No. Suggested a
n
Resulting f(n) Resulting initial conditions
1 1 0 a
1
= 1 and a
2
= 1
2 -1 0 a
1
= 1 and a
2
= 1
3 n (2-n) a
1
= 1 and a
2
= 2
We note that row 1 and row 2 are not linearly independent. We also note that in row 3,
we have a
n
= n which gives the correct f(n) but the initial conditions are not correct. We can
subtract row 1 from row 3 which gives a
n
= (n 1) with the correct initial conditions. Thus,
a
n
= (n 1) is the required solution.
Next we consider the following example.
a
n
(n 1)a
n1
+na
n2
= (n 1) for n > 1; a
0
= a
1
= 1.
We generalize this as,
a
n
(n 1)a
n1
+na
n2
= f(n) for n > 1; a
0
= a
1
= 1.
As before, we try various possibilities for a
n
and look for the resulting f(n) to get a repertoire
of recurrences. We summarize the work in the following table:
Row No. Suggested a
n
Resulting f(n) Resulting initial conditions
1 1 2 a
0
= a
1
= 1
2 n n 1 a
0
= 0 and a
1
= 1
3 n
2
n + 1 a
0
= 0 and a
1
= 1
From row 1 and row 3, by subtraction we nd that a
n
= (n
2
1) is a solution because it
results in f(n) = (n 1); however it gives the initial conditions a
0
= 1 and a
1
= 0. This
solution and the solution in the second row are linearly independent. We combine these to give
a
n
= (n n
2
+ 1) which gives the right initial conditions.
April 2007 43 CSE/NIT
Basic Combinatorics K. V. Iyer
13.4 Perturbation Method
The Perturbation Method is another technique to approximate the solution to a recurrence.
The method is nicely illustrated in the following example given in [?]. Consider the following
recurrence:
a
0
= 1; a
1
= 2 and a
n+1
= 2a
n
+a
n1
/n
2
, n > 1 (15)
In the perturbation step, we note that the last term contains the 1 / n
2
factor; we therefore
reason that it will bring a small contribution to the recurrence; hence, approximately,
a
n+1
= 2a
n
This yields a
n
= 2
n
which is an approximate solution. To correct the error involved, we consider
the exact recurrence,
b
n+1
= 2b
n
, n > 0; with b
0
= 1.
Then, b
n
= 2
n
which is exact. We now compare the two quantities a
n
and b
n
. Let,
P
n
= a
n
/b
n
= a
n
/2
n
which gives a
n
= 2
n
P
n
.
Using the last relation in (15) we get,
2
n+1
P
n+1
= 2 2
n
P
n
+ 2
n1
P
n1
/n
2
when n > 1.
Therefore, P
n+1
= P
n
+ (1/4n
2
)P
n1
, n > 0; P
0
= 1
Clearly the P
n
s are increasing. We see that,
P
n+1
P
n
(1 + (1/4n
2
)), n 1,
so that,
P
n+1

n

k=1
[1 + (1/4k
2
)].
The innite product
0
corresponding to the right hand side above converges monotonically to

0
=

k=1
(1 + (1/4k
2
)) = 1.46505 . . .
Thus P
n
is bounded above by
0
and as it is increasing, it must converge to a constant. We have
thus proved that, a
n
2
n
, for some constant < 1.46505.
April 2007 44 CSE/NIT
Basic Combinatorics K. V. Iyer
14 Solving Recurrences using Generating Functions
We next consider a general technique to solve linear recurrence relations. This is based on the
idea of generating functions. We begin with an introduction to generating functions. An innite
sequence a
0
, a
1
, a
2
, . . . can be represented as a power series in an auxiliary variable z. We write,
A(z) = a
0
+a
1
z +a
2
z
2
+. . . =

k0
a
k
z
k
. . . (16)
When it exists, A(z) is called the generating function of the sequence a
0
, a
1
, a
2
, . . ..
The theory of innite series says that:
1. If the series converges for a particular value z
0
of z then it converges for all values of z such
that [z[ < [z
0
[.
2. The series converges for some z ,= 0 if and only if the sequence [a
n
[
n/2
is bounded. (If
this condition is not satised, it may be that the sequence a
n
/n! is convergent.)
In practice, the convergence of the series may simply be assumed. When a solution is discovered
by any means, however sloppy, it may be justied independently say, by using induction.
We use the notation [z
n
]A(z) to denote the coecient of z
n
in A(z); that is, a
n
= [z
n
]A(z).
The following are easy to check:
1. If the given innite sequence is 1, 1, 1, . . . then it follows that the corresponding generating
function A(z) is given by,
A(z) = 1 +z +z
2
+z
3
+. . . = 1/(1 z).
2. If the given innite sequence is 1, 1/1!, 1/2!, 1/3!, 1/4!, . . . then
A(z) = 1 +z/1! +z
2
/2! +z
3
/3! +z
4
/4! +. . . = e
z
.
3. If the given innite sequence is 0, 1, 1/2, 1/3, 1/4, . . . then,
A(z) = z +z
2
/2 +z
3
/3 +z
4
/4 +. . . = ln(1/(1 z)).
April 2007 45 CSE/NIT
Basic Combinatorics K. V. Iyer
14.1 Convolution
Let A(z) and B(z) be the generating functions of the sequences a
0
, a
1
, a
2
, . . . and b
0
, b
1
, b
2
, . . .
respectively. The product A(z)B(z) is the series,
(a
0
+a
1
z +a
2
z
2
+. . .) (b
0
+b
1
z +b
2
z
2
+. . .)
= a
0
b
0
+ (a
0
b
1
+a
1
b
0
)z + (a
0
b
2
+a
1
b
1
+a
2
b
0
)z
2
+. . .
It is easily seen that, [z
n
]A(z)B(z) =

n
k=0
a
k
b
nk
. Therefore, if we wish to evaluate any sum
that has the general form
c
n
=
n

k=0
a
k
b
nk
(17)
and if the generating functions A(z) and B(z) are known then we have c
n
= [z
n
]A(z)B(z).
The sequence c
n
is called the convolution of the sequences a
n
and b
n
. In short, we
say that the convolution of two sequences corresponds to the product of the respective generating
functions. We illustrate this with an example.
From the Binomial Theorem, we know that, (1+z)
r
is the generating function of the sequence
C(r, 0), C(r, 1), C(r, 2), . . .. Thus we have,
(1 +z)
r
=

k0
C(r, k)z
k
and (1 +z)
s
=

k0
C(s, k)z
k
By multiplication, we get (1 +z)
r
(1 +z)
s
= (1 +z)
r+s
.
Equating the coecients of z
n
on both the sides we get,

k=0
C(r, k)C(s, n k) = C(r +s, n)
which is the well-known Vandermonde convolution.
When b
k
= 1 (for all k = 0, 1, 2, . . . ) , then from (12) we get, c
n
=

k=0
a
k
.
Thus, convolution of a given sequence with the sequence 1, 1, 1, . . . gives a sequence of
sums. The following examples are illustrative of this fact.
Example 14.1:
By taking the convolution of the sequence 1, 1, 1, . . . (whose generating function is 1/(1 z) )
with itself we can immediately deduce that 1/(1 - z)
2
is the generating function of the sequence
1, 2, 3, 4, 5, . . ..
April 2007 46 CSE/NIT
Basic Combinatorics K. V. Iyer
Example 14.2:
We can easily see that 1/(1 + z) is the generating function for the sequence 1, 1, 1, 1, . . ..
Therefore 1/(1 +z)(1 z) or 1/(1 z
2
) is the generating function of the sequence 1, 0, 1, 0, . . .
which is the convolution of the sequences 1, 1, 1, . . . and 1, 1, 1, 1, . . ..
14.2 Manipulations of generating functions
In the following, we assume F(z) and G(z) to be the respective generating functions of the innite
sequences f
n
and g
n
.
1. For some constants u and v we have,
uF(z) +vG(z) = u

n0
f
n
z
n
+v

n0
g
n
z
n
=

n0
(uf
n
+vg
n
)z
n
,
which is therefore the generating function of the sequence uf
n
+vg
n
.
2. Replacing z by cz where c is a constant, we get
G(cz) =

n0
g
n
(cz)
n
=

n0
c
n
g
n
z
n
which is the generating function for the sequence c
n
g
n
. Thus 1/(1 cz) is the generating
function of the sequence 1, c, c
2
, c
3
, . . ..
3. Given G(z) in a closed form we can get G

(z). Term by term dierentiation (when possible)


of the innite sum of G(z) yields,
G

(z) = g
1
+ 2g
2
z + 3g
3
z
2
+ 4g
4
z
3
+. . .
Thus G

(z) represents the innite sequence g


1
, 2g
2
, 3g
3
, 4g
4
, . . . i.e., (n +1)g
n+1
. Thus,
with a shift, we have brought down a factor of n into the terms of the original sequence
g
n
. Equivalently, zG

(z) is the generating function for ng


n
.
4. By term by term integration (when possible) of the innite sum of G(z), we have
_
z
0
G(t)dt = g
0
z + (1/2)g
1
z
2
+ (1/3)g
2
z
3
+ (1/4)g
3
z
4
+. . . =

n1
(1/n)g
n1
z
n
April 2007 47 CSE/NIT
Basic Combinatorics K. V. Iyer
Thus by integrating G(z) we get the generating function for the sequence g
n1
/n.
Example 14.3:
It is required to nd the generating function of the sequence 1
2
, 2
2
, 3
2
, . . ..
We have seen above that 1/(1 x)
2
is the generating function of the sequence 1, 2, 3, . . ..
By dierentiation, we can see that 2/(1 x)
3
is the generating function of the sequence
2.1, 3.2, 4.3, . . .. In this sequence, the term with index k is (k + 2)(k + 1) which can be written
as (k+1)
2
+k+1. We want the sequence a
k
where a
k
= (k+1)
2
. By subtracting the generating
function for the sequence 1, 2, 3, . . . from that for the sequence 2.1, 3.2, 4.3, . . . , we get the
required answer as [2/(1 x)
3
] [1/(1 x)
2
].
April 2007 48 CSE/NIT
Basic Combinatorics K. V. Iyer
Exercises
1. Let A = a
1
, a
2
, a
3
, a
4
, a
5
be a set of ve integers. Show that for any permutation
a
1
, a
2
, a
3
, a
4
, a
5
of A, the product
(a
1
a
1
)(a
2
a
2
) (a
5
a
5
)
is always divisible by 2.
2. This problem concerns one instance of what is known as Langfords Problem. A 27-digit
sequence includes the digits 1 through 9, three times each. There is just one digit between
the rst two 1s and between the last two 1s. There are just two digits between the rst
two 2s and between the last two 2s and so on. The problem asks to nd all such sequences.
The nave method is:
Step 1. Generate the rst/next sequence of 27-digits using the digits 1 through
9, each digit occuring exactly three times.
Step 2. Check if the current sequence satises the given constraint.
Step 3. Output the current sequence as a solution if it satises the constraint.
Step 4. If all sequences have been generated then stop; else go to Step 1.
How many sequences are examined in the above method?
Bonus: How is it possible to do better?
3. How many ways are there to choose three or more people from a set of eleven people?
4. Three boys and four girls are to sit on a bench. The boys must sit together and the girls
must sit together. In how many ways can this be done?
5. An urn contains 5 red marbles, 2 blue marbles and 5 green marbles. Assume that marbles
of the same color are indistinguishable. How many dierent sequences of marbles of length
four can be chosen?
6. Let X 1, 2, 3, 4, . . . , (2n 1) and let [X[ (n + 1). Prove the following result (due to
P. Erdos):
There are two numbers a, b X, with a < b such that a divides b.
In the above problem, if we prescribe [X[ = n, will the above result be still true?
April 2007 49 CSE/NIT
Basic Combinatorics K. V. Iyer
7. Find the approximate value (correct to three decimal places) of (1.02)
10
. (Hint: Use the
Binomial Theorem.)
8. Without using the general formula for (n) above, reason that when n = p

( is a natural
number) is a prime power, (n) can be expressed as p

(1 1/p).
9. If m and n are relatively prime, then argue that (mn) = (m)(n).
10. For an arbitrary natural number n prove that,

d|n
(d) = n (the sum is over all natural
numbers dividing n).
11. If p is a prime and n is a natural number, then argue that, (pn) = p(n) if p divides n and
(pn) = (p 1) (n), otherwise.
12. Argue that the number of partitions of a number n into exactly m terms is equal to the
number of partitions of n m into no more than m terms.
13. Find the number of ways in which eight rooks may be placed on a conventional 8 8
chessboard so that no rook can attack another and the white diagonal is free of rooks.
14. What is the number A
n
of ways of going up a staircase with n steps if we are allowed to
take one or two steps at a time?
15. Consider the evaluation of nn determinant by the usual method of expansion by cofactors.
If f
n
is the number of multiplications required then argue that f
n
satises the recurreence
f
n
= n(f
n1
+ 1), n > 1, f
1
= 0
Solve the above recurrence and hence show that f
n
en!, for all n > 1.
16. Without using induction prove that
n

i=1
i(i + 1)(i + 2) =
1
4
n(n + 1)(n + 2)(n + 3)
17. This problem is due to H. Larson (1977). Consider the innite sequence a
n
with a
1
= 1,
a
5
= 5, a
12
= 144 and a
n
+a
n+3
= 2a
n+2
.
Prove that a
n
is the nth Fibonacci number.
April 2007 50 CSE/NIT
Basic Combinatorics K. V. Iyer
18. Solve the recurrence relation
a
n
= 7a
n1
13a
n2
3a
n3
+ 18a
n4
where, a
0
= 5, a
1
= 3, a
2
= 6, a
3
= 21.
[Solution: Characteristic equation is (x+1)(x2)(x3)
2
, a
n
= 2(1)
n
+2
n
+2 3
n
n3
n
,
n 0.]
19. Consider the following recurrence:
a
n
6a
n1
7a
n2
= 0, n 5
with a
3
= 344, a
4
= 2400. Show that a
n
= 7
n
+ (1)
n+1
, n 3.
20. Consider the recurrence relation
a
n
= 6a
n1
9a
n2
,
with a
0
= 2 and a
1
= 3. Show that the associated generating function g(x) is given by
g(x) =
2 9x
1 6x + 9x
2
.
Hence obtain a
n
.
Solution: a
n
= (2 n) 3
n
, n 0.
21. Let N be the number of strings of length n made up of the letters x, y and z, where z occurs
an even number of times.
Show that N =
1
2
(3
n
+ 1).
22. How many sequences of length n can be composed from a, b, c, d in such a way that a and
b are never neighboring elements?
(Hint: Let x
n
= number of such sequences that start from a or b; let y
n
= number of such
sequences that start from c or d; form two recurrences involving x
n
and y
n
.)
23. The Moebius function is another number theoretic function. This exercise is to prove the
Moebius inversion formula from rst principles using the principle of inclusion-exclusion.
April 2007 51 CSE/NIT
Basic Combinatorics K. V. Iyer
References
[1] C. Berge, Priciples of Combinatorics, Academic Press, New York, 1971.
[2] G. Brassard and P. Bratley, Algorithmics: Theory and Practice, Prentice-Hall, 1988.
[3] C. Chuan-Chong and K. K. Meng, Principles and Techniques in Combinatorics, World
Scientic, Singapore, 1992.
[4] R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, Addison-Wesley,
Reading, MA, 1989.
[5] D. H. Greene and D. E. Knuth, Mathematics for the Analysis of Algorithms, Birkhauser,
Boston, 1982.
[6] D. E. Knuth, The Art of Computer Programming, v.1, Fundamental Algorithms, 3rd
edition, Addison-Wesley Longman, 1997.
[7] L. Lovasz, Combinatorial Problems and Exercises, North Holland, 1979.
[8] J. Matousek and J. Nesetril, Invitation to Discrete Mathematics, Clarendon Press, Ox-
ford, 1998.
[9] J. L. Mott, A. Kandel and T. P. Baker, Discrete Mathematics for Computer Science,
Reston Publishing Co., VA, 1983.
[10] E. S. Page and L. B. Wilson, An Introduction to Computational Combinatorics, Cam-
bridge University Press, Cambridge, 1979.
[11] R. Sedgewick and P. Flajolet, An Introduction to the Analysis of Algorithms, Addison-
Wesley, 1996.
April 2007 52 CSE/NIT

Vous aimerez peut-être aussi