Professional Documents
Culture Documents
FT
Instructor: Sanjib Sadhu
Department of CSE
RA
National Institute of Technology, Durgapur
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Pigeonhole Principle
FT
Pigeonhole Principle
If m pigeons are located in n pigeonholes (m > n), then there must
be a pigeonhole with more than one pigeon.
Example RA
If 10 pigeons are located in 9 pigeonholes, then there is a
pigeonhole with more than one pigeon.
Pigeonhone Principle
FT
Let m, n ∈ N. If m pigeons are placed in n holes, then there must
exist a hole containing at least d m
n e pigeons.
m
RA
than or equal to d m
n e − 1 pigeons. Therefore, the number of
pigeons= n(d n e − 1) ≤ n × (( m n−1
n + n ) − 1) = m + n − 1 − n < m
pigeons. It contradicts our assumption.
Examples
In a class of 13 students, at least two must be born in the
same month. Here, the 13 students are “pigeons” and the 12
FT
months are “pigeonholes”.
If 102 students took an exam with maximal score 100 points,
then at least two students will have the same score. The
students are “pigeons”, the numbers of points are
“pigeonholes”.
RA
A drawer contains 10 pairs of socks of different colors and you
pick some randomly. What minimum number guarantees a
pair of one color? The 10 colors are “pigeonholes”, so we need
to pick 11 to guarantee.
Among 100 integers a1 , . . . , a100 one can find two ai , aj , i 6= j,
whose difference is divisible by 97. Integers a1 , . . . , a100 are
“pigeons”, residues mod 97 are “pigeonholes”.
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Example
For any choice of six digits in the set S = {1, 2, . . . , 9} one can
find two chosen digits giving in sum 10.
FT
Solution : Pigeons here are digits and pigeonholes are 5 subsets
{1, 9}, {2, 8}, {3, 7}, {4, 6}, {5}. Among six chosen digits two will be in the same
subset, and thus, give in sum 10.
Example
RA
If there are n > 1 people who can shake hands with one another, then
there is always two persons who will shake hands with the same number
of people.
Example
In every sequence of n ∈ N integers a1 , . . . , an one can find several
FT
consecutive ones whose sum ai + ai+1 + . . . + aj is divisible by n.
Example
One has chosen 5 points inside an equilateral triangle with side 1.
FT
Prove that between some pair of chosen points the distance is ≤ 12
Example
27 points are aligned so that each row has 9 points and each column has
3 points. (A column is perpendicular to a row.) Each point is painted in
FT
red or blue. Prove that there exists a monochromatic rectangle (i.e. 4
vertices are of the same colour) with its sides parallel to the rows and
columns.
Solution Try to draw the points to see how they ‘behave’. If you try to
draw and paint them randomly, you will probably find that some columns
RA
are exactly the same. Actually, this is the way to the solution. Every
point may have 2 colours. Therefore, every column containing 3 points
has 23 = 8 colouring schemes. By Pigeonhole Principle, there are at least
d 98 e = 2 columns painted exactly the same. In each of these 2 columns,
by Pigeonhole Principle again, we have at least 2 points in the column
painted in the same colour. Obviously, these 4 points having the same
colour in these 2 columns form a rectangle with the desired properties.
Example
51 integers are chosen from 1, 2, 3, ..., 100. Prove that there are 2
distinct chosen integers such that one is a multiple of the other.
FT
Solution :
If we would like to use Pigeonhole Principle to solve this problem,
it seems that we have to partition {1, 2, 3, . . . , 100} into 50 subsets
such that every 2 elements of a subset have a relation that one is a
multiple of the other. In order to do this, we may consider the
RA
singletons of odd numbers {1}, {3}, . . . , {99}. Next, we append
these singletons. For each odd number k, we put
2k, 4k, 8k, . . . , 2i k, . . . into the set {k}. Each such subset is a
pigeonhole. (i.e. they are {1, 2, 4, . . . , 64}, {3, 6, 12, . . . , 96},
{5, 10, . . . , 80}, . . . , {97}, {99}). By Pigeonhole Principle,
51
d 50 e = 2 of them are in the same subset, so the larger one is a
multiple of the smaller one.
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Example
A chess player wants to prepare for a championship match by
playing some practice games in 77 days. She wants to play at least
FT
one game a day but no more than 132 games altogether. Show
that no matter how she schedules the games, there is a period of
consecutive days within which she plays exactly 21 games.
Solution: Let ai be the total number of games she plays up through
the i th day. Clearly the sequence a1 , a2 , . . . , a77 is a monotonically
RA
increasing sequence with a1 ≥ 1 and a77 ≤ 132. Now compute the
sequence a1 + 21, a2 + 21, . . . , a77 + 21 which again is a monotonically
increasing sequence with a77 + 21 ≤ 153. Since the values of the 154
numbers a1 , a2 , . . . , a77 , a1 + 21, . . . , a77 + 21 ranges from 1 to 153, two
of them must be the same (by Pigeonhole Principle). Moreover, because
both the sequence a1 , a2 , . . . , a77 and the sequence
a1 + 21, a2 + 21, . . . , a77 + 21 are monotonically increasing, we have
ai = aj + 21 for some ai and aj .
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Example
FT
Show that in a sequence of (n2 + 1) distinct integers, there is
either an increasing subsequence of length (n + 1) or a decreasing
subsequence of length (n + 1).
RA
2, 5, 1, 9, 45, 3, 70, 80, 21, 15
FT
yk is the the length of longest decreasing subsequence starting at
ak . Suppose there is no increasing subsequence or decreasing
subsequence of length n + 1 in the sequence a1 , a2 , . . . an2 +1 . That
is, the values of xk and yk lie between 1 and n for
k = 1, 2, . . . , n2 + 1. With only n2 distinct ordered pairs as possible
RA
labels for the (n2 + 1) integers, there must exist ai and aj in the
sequence that are labelled with the same ordered pair. However
this is impossible because if ai < aj , we must have xi > xj and if
ai > aj , we must have yi > yj . Consequently, we conclude that
there is either an increasing subsequence or a decreasing
subsequence of length n + 1 in the sequence a1 , a2 , . . . , an2 +1 .
Problem
No three diagonals of a convex decagon meet at the same point
inside the decagon, into how many line segments are the diagonals
FT
divided by their intersection?
RA
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Solution:
First of all the number of diagonals is equal to to
FT
C (10, 2) − 10 = 45 − 10 = 35 as there are C (10, 2) straight lines
joining the the pair of vertices, but 10 of these 45 lines are the
sides of the decagon. Since for every four vertices we can count
exactly one intersection between the diagonals (the decagon is
convex), there are total of C (10, 4) = 210 intersections between
RA
the diagonals. Since a diagonal is divided into (K + 1) straight line
segments when there are K intersecting points lying on it, and
since each intersecting point lies on two diagonals, the total
number of straight line segments into which the diagonals are
divided is 35 + 2 × 210 = 455.
Problem
Place r balls of the same colour in n number of boxes allowing as
many balls in a box as we wish. The number of ways to place the
−1)!
ball is (n+r
r !(n−1)! = C (n + r − 1, r )
FT
Solution: An easy way to see this result is to consider the problem
of arranging (n + 1) 1s and r 0s with a 1 at the beginning and a 1
at the end of each arrangement. If we consider the 1s as the inter
box partitions and the 0s as the balls, then every such arrangement
RA
corresponds to a way of placing r balls of the same colour in n
numbered boxes. For example, let n = 5 and r = 4, the sequence
1011001101 can be viewed as a placement of 4 balls in 5 boxes
having one ball in the first box, no ball in the second box, two balls
in the third box, no balls in the fourth box and one ball in the fifth
box. So the number of ways of arranging r 0s and n + 1 1s with 1s
−1)!
at both ends of an arrangement is (n+r
r !(n−1)! = C (n + r − 1, r )
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Example
You walk into a candy store and have enough money for 6 pieces
of candy. The store has chocolate (C), gummies (G), and horrible
FT
Chinese candy (H). How many different selections can you make?
FT
----|--|
||------
• Now the answer becomes obvious: we have 8 slots there and just
have to decide where to put the two dividers.
• There are C (8, 2) ways to do that, so C (8, 2) = 28 possible
selections. RA
• . . . or equivalently, there are C (8, 6) = 28 ways to place the
candy selections.
r-combination with repeatition
If we are selecting an r-combination from n elements with
repetition, there are C(n+r-1,r)=C(n+r-1,n-1) ways to do so.
Example
FT
How many solutions does this equation have in the non-negative
integers?
a + b + c = 100
Solution:
• In order to satisfy the equation, we have to select 100 “ones”,
RA
some that will contribute to a, some to b, some to c.
• In other words, we have balls labelled a, b, and c. We select 100
of them (with repetition) and that gives us a solution to the
equation. C(102,2) solutions.
Example
for i=1 to n do
FT
for j=1 to i do
for k=1 to j do
printf(“hello world”);
How many “hello world” will this program print?
Example
for i=1 to n do
for j=1 to i do
FT
for k=1 to j do
printf(“hello world”);
How many “hello world” will this program print?
FT
Problem
4 couples arrived at a party and were greeted by the host and the
hostess at the door. After several rounds of handshaking the host
asked the guests as well as the hostess (his wife) to indicate the
number of hands each one of them had shaken. He got different
RA
answers from each one. Given that no one shook hands with his or
her own spouse, how many hands had the hostess shaken?
Mountain Range
FT
We are seeking arrangements of n up-strokes and n down-strokes
that form valid mountain ranges. How many “mountain ranges”
can you form with n upstrokes and n downstrokes that all stay
above the original line? The following Table gives a list of the
possibilities for 1 ≤ n ≤ 3
RA
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Mountain Range
If we completely ignore whether the path is valid or not, we
have n up-strokes that we can choose from a collection of 2n
FT
available slots. In other words, ignoring path validity, we are
simply asking how many ways you can rearrange a collection
of n up-strokes and n down-strokes. The answer is C (2n, n).
Now we have to subtract off the bad paths. Every bad path
goes below the horizon for the first time at some point, so
RA
from that point on, reverse all the strokes → replace
up-strokes with down-strokes and vice-versa. It is clear that
the new paths will all wind up 2 steps below the horizon, since
they consist of (n − 1) up-strokes and (n + 1) down-strokes.
Conversely, every path that ends two steps below the horizon
must be of this form, so it corresponds to exactly one bad
path.
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Mountain Range
invalid path or bad path
FT
Level 0
RA
Level 0
Level -1
Level -2
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
Mountain Range
How many such bad paths are there? The same number as
FT
there are ways to choose the (n + 1) down-strokes from among
the 2n total strokes, or C (2n, n + 1). Thus the count of valid
mountain ranges, or Cn , is given by exactly the formula:
n
RA
Cn = C (2n, n) − C (2n, n + 1) = C (2n, n) −
=
1
n+1
C (2n, n) =
1
·
(2n)!
(n + 1) n!n!
n+1
C (2n, n)
Balanced Parentheses
FT
Problem
A string of parentheses is valid if there are an equal number of
open and closed parentheses and if you begin at the left as you
move to the right, add 1 each time you pass an open and subtract
RA
1 each time you pass a closed parenthesis, then the sum is always
non-negative. For example, “(()())” is valid, but “())()(” is not.
How many groupings are there for each value of n?
Balanced Parentheses
FT
RA
Instructor: Sanjib Sadhu Combinatorics
Pigeonhole Principle
Combinatorics
Combinations with Repetition
Catalan Number
In this problem, the symbol “(” and the “)” corresponds to “/”
FT
and “\”, respectively of Mountain range problem.
In our formal definition of a valid set of parentheses, we stated
that if you add one for open parentheses and subtract one for
closed parentheses that the sum would always remain
non-negative. The mountain range interpretation is that the
RA
mountains will never go below the horizon.
The solution to this problem is also the nth Catalan Number
Cn .
FT
RA
A
Stack Permutation
a b c d e
FT
RA
Instructor: Sanjib Sadhu Combinatorics