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

Combinatorics Notes

Embed Size (px)

DESCRIPTION

Prof KVI

Citation preview

Page 1: Combinatorics Notes

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

Page 2: Combinatorics Notes

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 Stirling’s 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 Euler’s φ-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

Page 3: Combinatorics Notes

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

Page 4: Combinatorics Notes

Basic Combinatorics K. V. Iyer

. . . combinatorics, a sort of glorified dice-throwing . . .

Robert Kanigel in The Man who knew Infinity: 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 first 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

Page 5: Combinatorics Notes

Basic Combinatorics K. V. Iyer

1 Introduction

Combinatorics is the science (and to some extent, the art) of counting and enumeration of config-

urations (it is understood that a configuration 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 configu-

rations. The word combinatorial was first used in the modern mathematical sense by Gottfried

Wilhelm Leibniz (1646–1716) 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 Jeff Miller’s 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 configuration.

• investigation into the existence/non-existence of a configuration with specified properties.

• counting and obtaining exact formulas for the number of configurations satisfying certain

specified properties.

• approximate counting of configurations with a given property.

• enumeration and classification of configurations.

• optimization in the sense of obtaining a configuration with specified properties so as to

minimize an associated cost function.

It is instructive to retain the above guidelines and look for specific 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 field, 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

Page 6: Combinatorics Notes

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 finite sets of objects.

2.1 Sum Rule and Product Rule

The sum rule or the principle of disjunctive counting. If a finite set X is the union of pairwise

disjoint nonempty subsets S1, S2, . . . , Sn, then |X| = |S1|+ |S2| + · · ·+ |Sn| where, |X| denotes

the number of elements in the set X.

The product rule or the principle of sequential counting. If S1, S2, . . . , Sn are nonempty finite sets,

then the number of elements in the cartesian product S1×S2× · · · ×Sn is |S1| × |S2| × · · · × |Sn|.

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

Page 7: Combinatorics Notes

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 6100

ways of their falling.

Example 2.3:

A self-dual 2-valued Boolean function is one whose definition remains unchanged if we change all

the 0’s to 1’s and all the 1’s to 0’s 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 0As an example, we consider a Boolean function in 3 variables. The function value is what is

to be assigned in defining the function. As the function is required to be self-dual, it is evident

that an arbitrary assignment (of 0’s and 1’s) of values cannot be made. The self-duality requires

that changing all 0’s to 1’s and all 1’s to 0’s does not change the function definition. 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 2n−1 independent assignments to the function value can be made. Thus,

the total number of self-dual 2-valued Boolean functions is 22(n−1).

April 2007 7 CSE/NIT

Page 8: Combinatorics Notes

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 five 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 43 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(nr

)which is to be read as “n choose r ”.

The following are basic results: P (n, r) = n!(n−r)! and C(n, r) = n!

r!(n−r)! where n! (read as

“n-factorial”) is the product 1 · 2 · 3 · · ·n.

3.1 Stirling’s 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, Sn =√

(2πn) · (n/e)n

That is, limn→∞

n!/Sn = 1. The following table gives the values of n! and the corresponding Sn

for the indicated n also indicates the percentage error in Sn.

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 fixed, it is possible to obtain (n − 1)! different

arrangements of the remaining objects. For any arrangement it is possible to shift the position of

April 2007 8 CSE/NIT

Page 9: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Table 1: Sn for the indicated n and percentage error in Sn

n n! Sn Percentageerror

8 40 320 39 902 1.03579 362 880 359 537 0.9213

10 3 628 800 3 598 696 0.829611 39 916 800 39 615 625 0.754512 479 001 600 475 687 486 0.691913 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 filled by one of n possibilities. Thus the answer is U(n, r) = nr.

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 = sor + s1

rn + s2rn

2 + · · ·+ srrn

r.

By definition, the coefficients skr are the Stirling Numbers of the first kind. These numbers

can be calculated from the following formulas:

s0r = 0, sr

r = 1

skr+1 = sk−1

r − rskr (1)

Proof. By definition, [x]r+1 = [xr](x− r). Again by definition, we have from the above equality,

· · ·+skr+1x

k + · · · = (· · ·+sk−1r xk−1 +sk

rxk + · · · )(x−r) Equating the coefficients of xk on both the

sides above, gives the required recurrence. From the above relations we can build the following

April 2007 9 CSE/NIT

Page 10: Combinatorics Notes

Basic Combinatorics K. V. Iyer

table:

skr k = 0 1 2 3 4

r = 1 0 1 0 0 02 0 -1 1 0 03 0 2 -3 1 04 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 (n−r) objects. This is exactly equivalent to choosing (n−r)

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 different 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

Page 11: Combinatorics Notes

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 different 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 f2. 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 − f2.

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 first select (r − 1)

objects from among (n − 1) objects and then introduce X in any of the r positions. This gives

the first 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

Page 12: Combinatorics Notes

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 2C(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 different

pairings of S are there?

Method 1: We pick an element say x from S. The number of ways to select x’s 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 u’s partner,

say v, is (2n− 3). Thus, the total number of ways of picking {x, y} and {u, v} is (2n− 1)(2n− 3).

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(2n− 2, 2) ways. It is easy to see that the total number of ways to form the different

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

Page 13: Combinatorics Notes

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

1n!

[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) ∈ S3|x < z and y < z}. Show by

counting |T | in two different ways that,

∑1≤k≤n

k2 = C(n + 1, 2) + 2C(n + 1, 3) · · · . (2)

We first show that the number on the left-hand side of 2 is |T |: In selecting (x, y, z) we first

fix z = 2. We then have ordered 3-tuples of the form (−,−, z). The number of ways of filling the

blanks is 1× 1 as z is greater than both x and y. Next we fix z = 3 to get ordered 3-tuples of the

form (−,−, z). As both 2 and 1 are less than the fixed z, the number of ways of filling 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 fixing z = 3, 4, . . . , n. Thus the total number of different 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 6= y in the 3-tuples of interest. For the first 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 u1, u2, . . . , umn+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

Page 14: Combinatorics Notes

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 li(−) be the length of the longest decreasing subsequence

with the first term ui(−) and let li(+) be the length of the longest increasing subsequence with

the first term ui(+).

Assume that the result is false. Then ui → (li(−), li(+)) defines a mapping of {u1, u2, . . . , umn+1}

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

ui > uj ⇒ li(−) > lj(−)⇒ (li(−), li(+)) 6= (lj(−), lj(+))

ui < uj ⇒ li(+) > lj(+)⇒ (li(−), li(+)) 6= (lj(−), lj(+))

Hence, |{u1, u2, . . . , umn+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

Page 15: Combinatorics Notes

Basic Combinatorics K. V. Iyer

We treat the 7 people as 7 objects. We create 2 boxes—one (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 five 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∑

x∈B

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 = {a1, a2, . . . , an}. Consider the following m subsets of A and the sum of their respective

April 2007 15 CSE/NIT

Page 16: Combinatorics Notes

Basic Combinatorics K. V. Iyer

elements:

Set A1 = {a1} − sum of the elements is a1

Set A2 = {a1, a2} − sum of the elements is a1 + a2

Set A3 = {a1, a2, a3} − sum of the elements is a1 + a2 + a3

. . . . . . . . . . . . . . .

Set Am = {a1, a2, ..., am} − sum of the elements is a1 + a2 + · · ·+ am.

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,

a1 ≡ r1 ( mod m)

a1 + a2 ≡ r2 ( mod m)

a1 + a2 + a3 ≡ r3 ( mod m)

a1 + a2 + · · ·+ am ≡ rm ( mod m)

where each ri (1 ≤ i ≤ m) is in {1, 2, . . . , (m− 1)}. Now, we consider (m− 1) boxes numbered 1

through (m− 1) and we distribute the integers r1 through rm to these boxes so that ri goes into

box i if r1 = i . By the Pigeon-Hole principle there must be one box containing an ri and an rj

both of which must be the same, say r. That is, we must have,

a1 + a2 + · · ·+ ai ≡ r ( mod m)

and a1 + a2 + · · ·+ aj ≡ r ( mod m),

where j > i without loss of generality.

Therefore, m divides the difference (a1 + a2 + · · · + aj) − (a1 + a2 + · · · + ai). Accordingly,

Aj \A1 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

Page 17: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Let us consider the distinct objects to be a1, a2, a3, . . . , an. We are interested in selecting

r-combinations from {∞ · a1,∞ · a2,∞ · a3, . . . ,∞ · an}.

Any r-combination will be of the form {x1 · a1, x2 · a2, . . . , xn · an} where the x1, x2, . . . , xn

are the repitition numbers, each being a non-negative integer and they add up to r. Thus the

number of r-combinations of {∞·a1,∞·a2,∞·a3, . . . ,∞·an} is equal to the number of solutions

of x1 + x2 + x3 + · · ·+ xn = r.

For each xi we put a bin and assign xi 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: first 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) 1’s and r 0’s. Counting

such binary numbers is easy: we have (n− 1 + r) positions and we have to choose r positions to

be occupied by the 0’s ( the remaining (n − 1) positions get filled by 1’s ). 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, x1 + x2 + · · · + xn = r, xi > 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

Page 18: Combinatorics Notes

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 a’s are replaced by

a1, a2, a3 it is easy to see that we will get 3!x permutations. Further if the 4b’s are replaced by

b1, b2, b3, b4 then we will get (4!)(3!)x permutations. In addition, if we replace the 2c’s by c1, c2

we will get (2!)(4!)(3!)x permutations. In the process we have generated the set { a1, a2, a3, b1,

b2, b3, b4, c1, c2, 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 q1, q2, . . . , qt be nonnegative integers such that n = q1 + q2 + . . . + qt . Also let a1, a2,

. . . , at be t distinct objects. Let P (n; q1, q2, . . . , qt) denote the number of n-permutations of the

n-combination of {q1 · a1, q2 · a2, . . . , qt · at}. By an argument similar to the above example we

have

P (n; q1, q2, . . . , qt) = n!/(q1! · q2! · . . . · qt!) =

C(n, q1)C(n− q1, q2)C(n− q1 − q2, q3) . . . C(n− q1 − q2 − . . .− qt−1, qt)

By substituting the formula for each term in the product, the last expression can be simplified 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 {A1, A2, . . . , At} of t subsets of S namely, A1, A2, . . . , At such that

S = A1 ∪A2 ∪ · · · ∪At,

and Ai ∩Aj = φ, for i 6= j.

This refers to unordered partition.

An ordered partition of S is firstly, a partition of S; secondly there is a specified 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

Page 19: Combinatorics Notes

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 (q1, q2, . . . , qt) , where |S| = n, is

P (n; q1, q2, . . . , qt) = n!/(q1! · q2! · · · · qt!)

We see this by choosing the q1 elements to occupy the first subset in C(n, q1) ways; the q2 elements

for the second subset in C(n − q1, q2) ways etc. Thus, the number of ordered partitions of the

type (q1, q2, . . . , qt) is

C(n, q1)C(n− q1, q2)C(n− q1 − q2, q3) . . . C(n− q1 − q2 − . . .− qt−1, qt)

which is equal to n!/(q1! · q2! · · · qt!).

Example 7.1:

In the game of bridge, the four players N , E, S and W are seated in a specified 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 (n2)!/(n!)n is an integer.

Consider a set of n2 elements. Partition this set into n-part partitions. Then the number of

ordered n-part partitions is (n2)!/(n!)n which has to be an integer.

April 2007 19 CSE/NIT

Page 20: Combinatorics Notes

Basic Combinatorics K. V. Iyer

We can also consider partitioning a set of objects into different 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 Smn

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 S1n + S2

n + . . . + Smn ). It

easily follows that,

S1n = Sn

n = 1.

Also, Skn+1 = Sk−1

n + kSkn, 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 k−1 classes and attach the class containing the sole member.

The number of partitions thus formed is Sk−1n .

2. The (n + 1)th object is not the sole member of any class: In this case, we first form the

partitions of the remaining n objects into k classes. This gives Skn partitions. In each such

partition we then add the (n+1)th object to one of the k classes. We thus get kSkn partitions

of the required type.

From (i) and (ii) above, the result follows.

April 2007 20 CSE/NIT

Page 21: Combinatorics Notes

Basic Combinatorics K. V. Iyer

The interpretation of Smn 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 (m− 1) classes. The class c can be

chosen in C(n− 1, r − 1) possible ways. Hence,

Smn =

n∑r=1

C(n− 1, r − 1)Sm−1n−r .

We can use the above relations to build the following table:

Smn m = 1 2 3 4 5 6 7

n = 1 1 0 0 0 0 0 02 1 1 0 0 0 0 03 1 3 1 0 0 0 04 1 7 6 1 0 0 05 1 15 25 10 1 0 06 1 31 90 65 15 1 07 1 63 301 350 140 21 1

8 Combinatorial Identities

There are many interesting combinatorial identities. Some of these identities are suggested by

the Pascal’s Triangle shown in Fig. 1. Pascal’s triangle is constructed by first writing down three

1’s in the form of a triangle (this corresponds to the first two rows in the figure). Any number

(other than the 1’s 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 1’s 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 Pascal’s triangle.

Newton’s 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: first 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 first 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

Page 22: Combinatorics Notes

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:

Pascal’s Identity: C(n, r) = C(n− 1, r) + C(n− 1, r − 1).

This is attributed to M. Stifel (1486–1567) and to Blaise Pascal (1623–1662).

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: fix a value for k where

0 ≤ k ≤ r; for each k distribute the k balls in the first (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) = 2n.

Consider finding 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 filling up of the bins (with a 1 or with a 0). This is equal

to 2n , 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

Page 23: Combinatorics Notes

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, n−r)(n−r)-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)xn + C(n, 1)xn−1y + C(n, 2)xn−2y2 + · · ·+ C(n, r)xn−ryr + · · ·+ C(n, n)yn

Note: For the definition 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 xn−ryr for each

April 2007 23 CSE/NIT

Page 24: Combinatorics Notes

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 coefficient of the term of the form xn−ryr in the expansion of (x + y)n. For

any given r, to get the term xn−ryr we select r of the y’s 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 coefficient of

xn−ryr as required by the theorem.

The binomial coefficients (of the type C(n, r)) appearing above occur in the Pascal’s triangle.

For a fixed n, we can obtain the ratio of the (k + 1)st bionomial coefficient of order n to the kth :

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 coefficient must occur in the “middle”. We use Stirling’s

approximation to estimate how big the binomial coefficients are:

C(n, n/2) =n!

(n/2)!=

(n/e)n√

(2nπ){(n/2e)n/2

√(nπ)}2

= 2n√

(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 = 2n or S = 2n−1. 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 2n−1.

Example 9.3:

April 2007 24 CSE/NIT

Page 25: Combinatorics Notes

Basic Combinatorics K. V. Iyer

To show that: 1 · C(n, 1) + 2 · C(n, 2) + 3 · C(n, 3) + · · · + n · C(n, n) = n2n−1, for each positive

integer n.

We use the Newton’s 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)] = n2n−1

giving the expression on the right.

The Multinomial Theorem: This concerns with the expansion of multinomials of the form

(x1 + x2 + . . . + xt)n.

Here, the role of the binomial coefficients gets replaced by the “multinomial coefficients”

P (n; q1, q2, . . . , qt) =n!

q1!q2! · · · qt!

where qi’s are non-negative integers and∑

qi = n. (recall that the multinomial coefficients

enumerate the ordered partitions of a set of n elements of the type (q1, q2, . . . , qt)).

Example 9.4:

By long multiplication we can get, (x1 + x2 + x3)3 = x31 + x3

2 + x33 + 3x2

1x2 + 3x21x3 + 3x1x

22

+ 3x1x23 + 3x2x

23 + 3x2

2x3+ 6x1x2x3.

To get the coefficient of, say, x2x23 we choose x2 from one of the factors and x3 from the

remaining two. This can be done in C(3, 1) · C(2, 2) = 3 ways; therefore the required coefficient

should be 3.

Example 9.5:

Find the coefficient of x41x

52x

63x

34 in (x1 + x2 + x3 + x4)18.

The product will occur as often as, x1 can be chosen from 4 out of the 18 factors, x2 from 5

out of the remaining 14 factors, x3 from 6 out of the remaining 9 factors and x4 from out of the

April 2007 25 CSE/NIT

Page 26: Combinatorics Notes

Basic Combinatorics K. V. Iyer

last 3 factors. Therefore the coefficient of x41x

52x

63x

34 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 x1, x2, . . . ,xt we have,

(x1 + x2 + · · ·+ xt)n =∑

P (n; q1, q2, ..., qt)xq11 xq2

2 · · ·xqtt

where the summation extends over all sets of non-negative integers q1, q2, . . . , qt with q1 + q2 +

· · ·+ qt = n.

To count the number of terms in the above expansion, we note that each term of the form xq11

, xq22 , . . . , xqt

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 (x1 + x2 + x3 + x4 +x5)10, the coefficient of x21x3x

34x

45 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 x1 = x2 = · · · = xt = 1, then for any positive interger t,

we have tn =∑

P (n; q1, q2, . . . , qt), where the summation extends over all sets of non-negative

integers q1, q2, . . . , qt with∑

qi = n.

April 2007 26 CSE/NIT

Page 27: Combinatorics Notes

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 first consider the case of two sets. If A and B are finite 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 five members can be formed

so that at least one of professor A or professor B is included?

Let A1 and A2 be the sets of committees that include professor A and professor B respectively.

Then the required number is |A1 ∪A2| . Now,

|A1| = C(9, 4) = 126 = |A2| and |A1 ∩A2| = C(8, 3) = 56.

Therefore it follows that |A1 ∪A2| = 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 finite sets then

|A ∪B ∪ C| = |A|+ |B|+ |C| − |A ∩B| − |A ∩ C| − |B ∩ C|+ |A ∩B ∩ C|

April 2007 27 CSE/NIT

Page 28: Combinatorics Notes

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 A1, A2, . . . , an are finite subsets of a universal set then,

|A1 ∪A2 ∪ · · · ∪An| =∑

|Ai| −∑

|Ai ∩Aj |+∑

|Ai ∩Aj ∩Ak| − · · ·

+(−1)n−1|A1 ∩A2 ∩ . . . ∩An| (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 = 24 − 1 = 15

terms on the right-hand side. In general there are,

C(n, 1) + C(n, 2) + C(n, 3) + · · ·+ C(n, n) = 2n − 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 A1 ∪ A2 ∪ · · · ∪ An is counted exactly once in the right

hand side of (6). Suppose that an element x ∈ A1 ∪A2 ∪ · · · ∪An is in exactly m (integer, ≥ 1)

of the sets considered on the right-hand side of (6); for definiteness, say

x ∈ A1, x ∈ A2, . . . , x ∈ Am and x /∈ Am+1, . . . , x /∈ An.

Then x will be counted in each of the terms |Ai|, for i = 1, . . . ,m; in other words x will be counted

C(m, 1) times in the “∑|Ai| term” on right-hand side of (6). Also, x will be counted C(m, 2)

times in the “∑|Ai ∩Aj | term” on right-hand side of (6) since there are C(m, 2) pairs of sets Ai,

April 2007 28 CSE/NIT

Page 29: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Aj where x is in both Ai and Aj . Likewise x is counted C(m, 3) times in the “∑|Ai ∩ Aj ∩ Ak|

term” since there are C(m, 3) 3-combinations of Ai , Aj and Ak such that x ∈ Ai, x ∈ Aj and

x ∈ Ak. 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)m−1C(m,m)

number of times. Now, we must show that, this last expression is 1. Expanding (m− 1)m by the

Binomial Theorem we get,

0 = C(m, 0)− C(m, 1) + C(m, 2) + · · ·+ (−1)m−1C(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 Euler’s φ-function

If n is a positive integer, by definition, φ(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 Ai be the subset of U consisting of those integers divisible by pi. The integers in U

relatively prime to n are those in none of the subsets A1, A2, . . . , Ak. So,

φ(n) = |A′1 ∩A′2 ∩ · · · ∩A′k| = |U | − |A1 ∪A2 ∪ · · · ∪Ak|

If d divides n, then there are n/d multiples of d in U . Hence,

|Ai| = n/pi, |Ai ∩Aj | = n/pipj · · · , |A1 ∩A2 ∩ · · · ∩Ak| = n/p1p2 . . . pk.

Thus by Inclusion-Exclusion Principle,

φ(n) = n−∑

i

n/pi +∑

1≤i≤j≤k

n/pipj + · · ·+ (−1)k(n/p1p2 · · · pk).

April 2007 29 CSE/NIT

Page 30: Combinatorics Notes

Basic Combinatorics K. V. Iyer

This is equal to the product n(1− 1

p1

)(1− 1

p2

)· · ·

(1− 1

pk

).

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 3rd 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 first 4 steps of the sieve method.

Let U be the set of integers x such that 1 ≤ x ≤ 1000. Let A1, A2, A3, A4 be the sets of

elements (of U) divisible by 2, 3, 5 and 7 respectively. Then, A1 ∪ A2 ∪ A3 ∪ A4 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

Page 31: Combinatorics Notes

Basic Combinatorics K. V. Iyer

|(A1 ∪A2 ∪A3 ∪A4)′| . We know that,

|A1| = 1000/2 = 500; |A2| = 1000/3 = 333;

|A3| = 1000/5 = 200; |A4| = 1000/7 = 142;

|A1 ∩A2| = 1000/6 = 166; |A1 ∩A3| = 1000/10 = 100;

|A1 ∩A4| = 1000/14 = 71; |A2 ∩A3| = 1000/15 = 66;

|A2 ∩A4| = 1000/21 = 47; |A3 ∩A4| = 1000/35 = 28;

|A1 ∩A2 ∩A3| = 1000/30 = 33; |A1 ∩A2 ∩A4| = 1000/42 = 23;

|A1 ∩A3 ∩A4| = 1000/70 = 14; |A2 ∩A3 ∩A4|= 1000/106 = 9;

|A1 ∩A2 ∩A3 ∩A4| = 1000/210 = 4

Then, |A1 ∪A2 ∪A3 ∪A4| =

(500 + 333 + 200 + 142)− (166 + 100 + 71 + 66 + 47 + 28) + (33 + 23 + 14 + 9)− 4 = 772.

Therefore, |(A1 ∪A2 ∪A3 ∪A4)′| = 1000− 772 = 228.

11 Derangements

Derangements are permutations of {1, . . . , n} in which none of the n elements appears in its

‘natural’ place. Thus, (i1, i2, . . . , in) is a derangement if i1 6= 1, i2 6= 2, . . . , and in 6= n.

Let Dn denote the number of derangements of (1, 2, . . . , n). It follows that D1 = 0; D2 = 1,

because (2, 1) is a derangement; D3 = 2 because (2, 3, 1) and (3, 1, 2) are the only derangements

of (1, 2, 3). We will determine Dn using the Inclusion-Exclusion principle.

Let U be the set of all n! permutations of {1, 2, . . . , n}. For each i, let Ai be the set of

permutations such that element i is in its correct place; that is, all permutations (b1, b2, . . . , bn)

such that bi = 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 Dn.

Now, the permutations in A1 are all of the form (1, b2, . . . , bn) where (b2, . . . , bn) is a permu-

tation of {2, . . . , n}. Thus |A1| = (n− 1)!. Similarly it follows thet |Ai| = (n− 1)!.

Likewise, A1 ∩A2 is the set of permutations of the form (1, 2, b3, . . . , bn), so that |A1 ∩A2| =

(n−2)!. We can similarly argue, |Ai∩Aj | = (n−2)! for all admissible pairs of values of i, j, i 6= j.

April 2007 31 CSE/NIT

Page 32: Combinatorics Notes

Basic Combinatorics K. V. Iyer

For any integer k, where 1 ≤ k ≤ n, the permutations in A1 ∩A2 ∩ . . . ∩Ak are of the form

(1, 2, . . . , k, bk+1, . . . , bn)

where (bk+1, . . . , bn) is a permutations of (k + 1, . . . , n). Thus, |A1 ∩A2 ∩ . . . ∩Ak| = (n− k)! .

More generally, we have |Ai1 ∩Ai2 ∩ . . . ∩Aik| = (n− k)! for {i1, i2, . . . , ik}, a k-combination

of {1, 2, . . . , n}. Therefore,

|(A′1 ∩A′2∩A′3 ∩ · · · ∩A′n)| = |U | − |A1 ∪A2 ∪ . . . ∪An|

= n!− C(n, 1)(n− 1)! + C(n, 2)(n− 2)! + . . . + (−1)nC(n, n)

= n!− n!1!

+n!2!− n!

3!+ . . . + (−1)n n!

n!.

Thus, Dn = n![1− 1

1! + 12! −

13! + . . . + (−1)n 1

n!

].

We can get a quick approximation to Dn 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 = (Dn/n!) + (−1)n+1(1/(n + 1)!) + (−1)n+2(1/(n + 2)!) + . . .

or |e−1 − (Dn/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 Dn. For example, D8 = 14833 and the value of 8!/e is about 14832.89906.

A different approach leads to a recurrence relation for Dn . 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 kth position (1 < k ≤ n) and k is displaced to the 1st

position: In this case, the total number of derangements of is equal to the number of

derangements of the set of n−2 numbers {2, 3, . . . , k−1, k +1, ..., n}. The required number

is thus Dn−2.

2. The integer 1 is displaced to the kth position (1 < k ≤ n) but k is displaced to a position

different from the 1st position: These are precisely the derangements of the set of n − 1

April 2007 32 CSE/NIT

Page 33: Combinatorics Notes

Basic Combinatorics K. V. Iyer

numbers {k, 2, 3, . . . , k − 1, k + 1, ..., n}. Clearly, any derangement will displace the integer

k from the 1st position. The required number is thus Dn−1.

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,

Dn = (n− 1)(Dn−1 + Dn−2)

By algebraic manipulations, it can be shown that Dn − nDn−1 = (−1)n, for n ≥ 2. This

recurrence relation when solved with the initial condition gives,

Dn = n!n−1∑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 definition. We proceed to prove the first 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. Define a mapping φ :

April 2007 33 CSE/NIT

Page 34: Combinatorics Notes

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 1’s 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 6n = 1 1 0 0 0 0 0

2 1 1 0 0 0 03 1 1 1 0 0 04 1 2 1 1 0 05 1 2 2 1 1 06 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 figure by 90o clockwise and by taking a mirror reflection) that the conjugate

partition of 5 + 3 + 2 + 2 is 4 + 4 + 2 + 1 + 1.

April 2007 34 CSE/NIT

Page 35: Combinatorics Notes

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 defines 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

defines a partition of 2n (as we are adding n 1’s) 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

Different types of recurrence relations (also known as difference 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

Page 36: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Example 13.1:

The number Dn of derangements of the integers (1, 2, . . . , n) as we have seen in section *** satisfies

the recurrence relation, Dn − nDn−1 = (−1)n, for n ≥ 2 with D1 = 0. The easiest way to solve

this recurrence relation is to rewrite it as

Dn

n!− Dn−1

(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 bn/2c and dn/2e 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 Master’s method is well-known.

April 2007 36 CSE/NIT

Page 37: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Example 13.3:

Consider the problem of finding the number of binary sequences of length n which do not contain

two consecutive 1’s.

Let wn be the number of such sequences. Let un be the number of such sequences whose last

digit is a 1. Also, let vn be the number of such sequences whose last digit is a 0. Obviously,

wn = un + vn.

Consider extending any sequence of the required type from length n− 1 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 difficult to reason that un and vn can be counted as given by the following recurrence

relations:

vn = vn−1 + un−1 and un = vn−1.

These lead to the equations,

vn = vn−1 + vn−2 and un = un−1 + un−2

which when added give the recurrence relation,

wn = wn−1 + wn−2.

This equation is the same as that for Fibonacci numbers, which can be solved with the initial

conditions w1 = 2 and w2 = 3.

Example 13.4:

A circular disk is divided into n sectors. There are p different 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

Page 38: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Let un 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 differently. 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 un−2 ways. Thus, we

have the following recurrence relation:

un = (p− 2)un−1 + (p− 1)un−2

with the initial conditions, u2 = p(p− 1)andu3 = p(p− 1)(p− 2).

The solution can be obtained as, un = (p− 1)[(p− 1)n−1 + (−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,

an = f(an−1, an−2, . . . , an−i), where n ≥ i

Here we have a recurrence with “finite history” as an depends on a fixed number of earlier values.

If an 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,

c0an + c1an−1 + ... + ckan−k = 0. (9)

The above equation is linear as it does not contain terms like an−i · an−j , a2n−i and so on; it is

homogeneous as the linear combination of an−i is zero; it is with constant coefficients because the

ci’s are constants. For example, the well-known Fibonacci Sequence 0, 1, 1, 2, 3, 5, 8, 13, 21,

April 2007 38 CSE/NIT

Page 39: Combinatorics Notes

Basic Combinatorics K. V. Iyer

34, . . . is defined by the linear homogeneous recurrence, fn = fn−1 + fn−2 , when n ≥ 2 with the

initial conditions, f0 = 0 and f1 = 1.

It is easy to see that if fn and gn are solutions to (9), then so does a linear combinations of

fn and gn say pfn + qgn , where p and q are constants. To solve (9), we try an = xn where x is

an unknown constant. If an = xn is used in (9) we should have,

c0xn + c1x

n−1 + . . . + ckxn−k = 0.

The solution x = 0 is trivial; otherwise, we must have

p(x) ≡ coxk + c1x

k−1 + . . . + ck = 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

fn − fn−1 − fn−2 = 0. (10)

The characteristic equation is x2 − x− 1 = 0. The roots r1, r2 of this equation are given by,

r1 = (1 +√

5)/2 and r2 = (1−√

5)/2.

So, the general solution of (10) is, fn = c1rn1 + c2r

n2 .

Using the initial conditions f0 = 0 and f1 = 1 we get, c1 + c2 = 0 and c1r1 + c2r2 = 1 which

give, c1 = 1/√

5 and c2 = −1/√

5.

Thus the nth Fibonacci number fn−1 is given by,

fn−1 =1√5

(1 +√

52

)n−1− 1√

5

(1−√

52

)n−1

It is interesting to observe that the solution of the above recurrence which has integer coefficients

and integer initial values, involves irrational numbers.

Example 13.6:

Consider the relation,

an − 6an−1 + 11an−2 − 6an−3 = 0, n > 2

April 2007 39 CSE/NIT

Page 40: Combinatorics Notes

Basic Combinatorics K. V. Iyer

with a0 = 1, a1 = 3 and a2 = 5.

From the given equation we directly write its chracteristic equation as,

x3 − 6x2 + 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, an = A1n + B2n + C3n.

Applying the initial conditions, we get,

a0 = 1 = A + B + C; a1 = 3 = A + 2B + 3C; and a2 = 5 = A + 4B + 9C

which yield, A = −2, B = 4 and C = −1.

Hence the solution is given by an = −2 + 4.2n − 3n.

We next deal with the case when the characteristic equation has multiple roots. Let the

characteristic polynomial p(x) be,

p(x) = coxk + c1x

k−1 + · · ·+ ck.

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)2q(x), where q(x) is of degree (k − 2).

For every n ≥ k consider the nth degree polynomials,

un(x) = c0xn + c1x

n−1 + . . . + ckxn−k

and vn(x) = c0nxn + c1(n− 1)xn−1 + · · ·+ ck(n− k)xn−k.

We note that, vn(x) = xu′n(x).

April 2007 40 CSE/NIT

Page 41: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Now, un(x) = xn−kp(x) = xn−k(x− r)2q(x) = (x− r)2[xn−kq(x)]

So, u′n(r) = 0, which implies that vn(r) = ru′n(r) = 0, for all n ≥ k.

That is, c0nrn + c1(n− 1)rn−1 + · · ·+ ck(n− k)rn−k = 0.

From (9), we conclude an = nrn is also a solution to the given recurrence.

More generally, if root r has multiplicity m, then an = rn, an = nrn, an = n2rn, . . . ,

an = nm−1rn all are distinct solutions to the recurrence.

Example 13.7:

Consider the recurrence, an − 11an−1 + 39an−2 − 45an−3 = 0, when n > 3 with a0 = 0, a1 = 1

and a2 = 2.

We can write the characteristic equation as

x3 − 11x2 + 39x− 45 = 0,

the roots of which are 3, 3 and 5. Hence, the general solution can be written as

an = (A + Bn)3n + C5n.

Using the initial conditions, we get a0 = A + C = 0; a1 = 3(A + B) + 5C = 1; and a2 =

9(A + 2B) + 25C = 2. This gives, A = 1, B = 1 and C = −1.

Hence the required solution is given by,

an = (1 + n)3n + 5n.

13.2 Inhomogeneous Equations

Inhomogeneous equations are more difficult to handle and linear combinations of the different

solutions may not be a solution. We begin with a simple case.

c0an + c1an−1 + · · ·+ ckan−k = bnp(n).

April 2007 41 CSE/NIT

Page 42: Combinatorics Notes

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,

an − 3an−1 = 5n (11)

Multiplying by 5, we get 5an − 15an−1 = 5n+1

Replacing n by n− 1, we get 5an−1 − 15an−2 = 5n (12)

Subtracting (12) from (11), an − 8an−1 + 15an−2 = 0 (13)

The corresponding characteristic polynomial is x2 − 8x + 15 = (x − 3)(x − 5) and so we can

write the general solution as,

an = A3n + B5n (14)

We can observe that 3n and 5n 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 a1 = 3a0 + 5, where a0 is the initial condition.

From (14) we get, A + B = a0 and 3A + 5B = a1 = 3a0 + 5.

Therefore, we should have, A = a0 − 5/2 and B = 5/2.

Hence, an = [(2a0 − 5)3n + 5n+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,

an − nan−1 + (n− 2)an−2 = (2− n),

with the initial condition a1 = 0 and a2 = 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

Page 43: Combinatorics Notes

Basic Combinatorics K. V. Iyer

equation,

an − nan−1 + (n− 2)an−2 = f(n).

We now try various possible candidate solutions for an, 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 an Resulting f(n) Resulting initial conditions

1 1 0 a1 = 1 and a2 = 1

2 -1 0 a1 = −1 and a2 = −1

3 n (2-n) a1 = 1 and a2 = 2

We note that row 1 and row 2 are not linearly independent. We also note that in row 3,

we have an = n which gives the correct f(n) but the initial conditions are not correct. We can

subtract row 1 from row 3 which gives an = (n − 1) with the correct initial conditions. Thus,

an = (n− 1) is the required solution.

Next we consider the following example.

an − (n− 1)an−1 + nan−2 = (n− 1) for n > 1; a0 = a1 = 1.

We generalize this as,

an − (n− 1)an−1 + nan−2 = f(n) forn > 1; a0 = a1 = 1.

As before, we try various possibilities for an and look for the resulting f(n) to get a “repertoire”

of recurrences. We summarize the work in the following table:

Row No. Suggested an Resulting f(n) Resulting initial conditions

1 1 2 a0 = a1 = 1

2 n n− 1 a0 = 0 and a1 = 1

3 n2 n + 1 a0 = 0 and a1 = 1

From row 1 and row 3, by subtraction we find that an = (n2 − 1) is a solution because it

results in f(n) = (n − 1); however it gives the initial conditions a0 = −1 and a1 = 0. This

solution and the solution in the second row are linearly independent. We combine these to give

an = (n− n2 + 1) which gives the right initial conditions.

April 2007 43 CSE/NIT

Page 44: Combinatorics Notes

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:

a0 = 1; a1 = 2 and an+1 = 2an + an−1/n2, n > 1 (15)

In the perturbation step, we note that the last term contains the “1 / n2” factor; we therefore

reason that it will bring a small contribution to the recurrence; hence, approximately,

an+1 = 2an

This yields an = 2n which is an approximate solution. To correct the error involved, we consider

the exact recurrence,

bn+1 = 2bn, n > 0; with b0 = 1.

Then, bn = 2n which is exact. We now compare the two quantities an and bn. Let,

Pn = an/bn = an/2n which gives an = 2nPn.

Using the last relation in (15) we get,

2n+1Pn+1 = 2× 2nPn + 2n−1Pn−1/n2 when n > 1.

Therefore, Pn+1 = Pn + (1/4n2)Pn−1, n > 0;P0 = 1

Clearly the Pn’s are increasing. We see that,

Pn+1 ≤ Pn(1 + (1/4n2)), n ≥ 1,

so that,

Pn+1 ≤n∏

k=1

[1 + (1/4k2)].

The infinite product α0 corresponding to the right hand side above converges monotonically to

α0 =∞∏

k=1

(1 + (1/4k2)) = 1.46505 . . .

Thus Pn is bounded above by α0 and as it is increasing, it must converge to a constant. We have

thus proved that, an ∼ α · 2n, for some constant α < 1.46505.

April 2007 44 CSE/NIT

Page 45: Combinatorics Notes

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 infinite

sequence {a0, a1, a2, . . .} can be represented as a power series in an auxiliary variable z. We write,

A(z) = a0 + a1z + a2z2 + . . . =

∑k≥0

akzk . . . (16)

When it exists, A(z) is called the generating function of the sequence {a0, a1, a2, . . .}.

The theory of infinite series says that:

1. If the series converges for a particular value z0 of z then it converges for all values of z such

that |z| < |z0|.

2. The series converges for some z 6= 0 if and only if the sequence {|an|n/2} is bounded. (If

this condition is not satisfied, it may be that the sequence {an/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 justified independently say, by using induction.

We use the notation [zn]A(z) to denote the coefficient of zn in A(z); that is, an = [zn]A(z).

The following are easy to check:

1. If the given infinite sequence is {1, 1, 1, . . .} then it follows that the corresponding generating

function A(z) is given by,

A(z) = 1 + z + z2 + z3 + . . . = 1/(1− z).

2. If the given infinite sequence is {1, 1/1!, 1/2!, 1/3!, 1/4!, . . .} then

A(z) = 1 + z/1! + z2/2! + z3/3! + z4/4! + . . . = ez.

3. If the given infinite sequence is {0, 1, 1/2, 1/3, 1/4, . . .} then,

A(z) = z + z2/2 + z3/3 + z4/4 + . . . = ln(1/(1− z)).

April 2007 45 CSE/NIT

Page 46: Combinatorics Notes

Basic Combinatorics K. V. Iyer

14.1 Convolution

Let A(z) and B(z) be the generating functions of the sequences {a0, a1, a2, . . .} and {b0, b1, b2, . . .}

respectively. The product A(z)B(z) is the series,

(a0 + a1z + a2z2 + . . .)× (b0 + b1z + b2z

2 + . . .)

= a0b0 + (a0b1 + a1b0)z + (a0b2 + a1b1 + a2b0)z2 + . . .

It is easily seen that, [zn]A(z)B(z) =∑n

k=0 akbn−k. Therefore, if we wish to evaluate any sum

that has the general form

cn =n∑

k=0

akbn−k (17)

and if the generating functions A(z) and B(z) are known then we have cn = [zn]A(z)B(z).

The sequence {cn} is called the convolution of the sequences {an} and {bn}. 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 =∑k≥0

C(r, k)zk and (1 + z)s =∑k≥0

C(s, k)zk

By multiplication, we get (1 + z)r(1 + z)s = (1 + z)r+s.

Equating the coefficients of zn 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 bk = 1 (for all k = 0, 1, 2, . . . ) , then from (12) we get, cn =∑

k=0 ak.

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

Page 47: Combinatorics Notes

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− z2) 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 infinite

sequences {fn} and {gn}.

1. For some constants u and v we have,

uF (z) + vG(z) = u∑n≥0

fnzn + v∑n≥0

gnzn =∑n≥0

(ufn + vgn)zn,

which is therefore the generating function of the sequence {ufn + vgn} .

2. Replacing z by cz where c is a constant, we get

G(cz) =∑n≥0

gn(cz)n =∑n≥0

cngnzn

which is the generating function for the sequence {cngn}. Thus 1/(1− cz) is the generating

function of the sequence {1, c, c2, c3, . . .}.

3. Given G(z) in a closed form we can get G′(z). Term by term differentiation (when possible)

of the infinite sum of G(z) yields,

G′(z) = g1 + 2g2z + 3g3z2 + 4g4z

3 + . . .

Thus G′(z) represents the infinite sequence {g1, 2g2, 3g3, 4g4, . . .} i.e., {(n + 1)gn+1}. Thus,

with a shift, we have “brought down a factor of n” into the terms of the original sequence

{gn}. Equivalently, zG′(z) is the generating function for {ngn}.

4. By term by term integration (when possible) of the infinite sum of G(z), we have∫ z

0G(t)dt = g0z + (1/2)g1z

2 + (1/3)g2z3 + (1/4)g3z

4 + . . . =∑n≥1

(1/n)gn−1zn

April 2007 47 CSE/NIT

Page 48: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Thus by integrating G(z) we get the generating function for the sequence {gn−1/n}.

Example 14.3:

It is required to find the generating function of the sequence {12, 22, 32, . . .}.

We have seen above that 1/(1− x)2 is the generating function of the sequence {1, 2, 3, . . .}.

By differentiation, 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 {ak} where ak = (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

Page 49: Combinatorics Notes

Basic Combinatorics K. V. Iyer

Exercises

1. Let A = {a1, a2, a3, a4, a5} be a set of five integers. Show that for any permutation

aπ1, aπ2, aπ3, aπ4, aπ5 of A, the product

(a1 − aπ1)(a2 − aπ2) · · · (a5 − aπ5)

is always divisible by 2.

2. This problem concerns one instance of what is known as Langford’s Problem. A 27-digit

sequence includes the digits 1 through 9, three times each. There is just one digit between

the first two 1’s and between the last two 1’s. There are just two digits between the first

two 2’s and between the last two 2’s and so on. The problem asks to find all such sequences.

The naıve method is:

Step 1. Generate the first/next sequence of 27-digits using the digits 1 through

9, each digit occuring exactly three times.

Step 2. Check if the current sequence satisfies the given constraint.

Step 3. Output the current sequence as a solution if it satisfies 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 different 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

Page 50: Combinatorics Notes

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 An 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 n×n determinant by the usual method of expansion by cofactors.

If fn is the number of multiplications required then argue that fn satisfies the recurreence

fn = n(fn−1 + 1), n > 1, f1 = 0

Solve the above recurrence and hence show that fn ≤ en!, for all n > 1.

16. Without using induction prove that

n∑i=1

i(i + 1)(i + 2) =14n(n + 1)(n + 2)(n + 3)

17. This problem is due to H. Larson (1977). Consider the infinite sequence an with a1 = 1,

a5 = 5, a12 = 144 and an + an+3 = 2an+2.

Prove that an is the nth Fibonacci number.

April 2007 50 CSE/NIT

Page 51: Combinatorics Notes

Basic Combinatorics K. V. Iyer

18. Solve the recurrence relation

an = 7an−1 − 13an−2 − 3an−3 + 18an−4

where, a0 = 5, a1 = 3, a2 = 6, a3 = −21.

[Solution: Characteristic equation is (x+1)(x− 2)(x− 3)2, an = 2(−1)n +2n +2 · 3n−n3n,

n ≥ 0.]

19. Consider the following recurrence:

an − 6an−1 − 7an−2 = 0, n ≥ 5

with a3 = 344, a4 = 2400. Show that an = 7n + (−1)n+1, n ≥ 3.

20. Consider the recurrence relation

an = 6an−1 − 9an−2,

with a0 = 2 and a1 = 3. Show that the associated generating function g(x) is given by

g(x) =2− 9x

1− 6x + 9x2.

Hence obtain an.

Solution: an = (2− n) · 3n, 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 = 12(3n + 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 xn = number of such sequences that start from a or b; let yn = number of such

sequences that start from c or d; form two recurrences involving xn and yn.)

23. The Moebius function is another number theoretic function. This exercise is to prove the

Moebius inversion formula from first principles using the principle of inclusion-exclusion.

April 2007 51 CSE/NIT

Page 52: Combinatorics Notes

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

Scientific, 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