Lecture 4: Counting, Pigeonhole Principle, Permutations, Combinations
Lecture 4: Counting, Pigeonhole Principle, Permutations, Combinations
Lecture 4: Counting, Pigeonhole Principle, Permutations, Combinations
Hacettepe University
http://web.cs.hacettepe.edu.tr/∼bbm205
Resources:
Kenneth Rosen, Discrete Mathematics and App.
http://www.inf.ed.ac.uk/teaching/courses/dmmr
Chapter Summary
A × B = {(a, b) | a ∈ A ∧ b ∈ B}
Product Rule
If A and B are finite sets, then: |A × B| = |A| · |B|.
A × B = {(a, b) | a ∈ A ∧ b ∈ B}
Product Rule
If A and B are finite sets, then: |A × B| = |A| · |B|.
{s2 , s4 , s5 , . . . , sm } ∼
= 0 1 0 1 1 ... 1
| {z }
m
Number of Functions
For all finite sets A and B, the number of distinct functions, f : A → B,
mapping A to B is:
|B||A|
(f : A → B) ∼
= f (a1 ) f (a2 ) f (a3 ) ... f (am )
By the product rule, there are nm such strings of length m.
Sum Rule
If A and B are finite sets that are disjoint (meaning A ∩ B = ∅), then
|A ∪ B| = |A| + |B|
Subtraction Rule
For any finite sets A and B (not necessarily disjoint),
|A ∪ B| = |A| + |B| − |A ∩ B|
A A∩B B
Example: How many bit strings of length 8 either start with a 1 bit or
end with the two bits 00?
Example: How many bit strings of length 8 either start with a 1 bit or
end with the two bits 00?
Solution:
Number of bit strings of length 8 that start with 1: 27 = 128.
Number of bit strings of length 8 that end with 00: 26 = 64.
Number of bit strings of length 8 that start with 1 and end with 00:
25 = 32.
Applying the subtraction rule, the number is 128 + 64 − 32 = 160.
Pigeonhole Principle
For any positive integer k , if k + 1 objects (pigeons) are placed in k
boxes (pigeonholes), then at least one box contains two or more
objects.
Proof: Suppose no box has more than 1 object. Sum up the number
of objects in the k boxes. There can’t be more than k .
Contradiction.
Pigeonhole Principle (rephrased more formally)
If a function f : A → B maps a finite set A with |A| = k + 1 to a finite set
B, with |B| = k , then f is not one-to-one.
(Recall: a function f : A → B is called one-to-one if ∀a1 , a2 ∈ A, if
a1 6= a2 then f (a1 ) 6= f (a2 ).)
“At least d students in this course were born in the same month.” (1)
“At least d students in this course were born in the same month.” (1)
“At least d students in this course were born in the same month.” (1)
Permutation
A permutation of a set S is an ordered arrangement of the elements
of S.
In other words, it is a sequence containing every element of S exactly
once.
(π : S → S) ∼
= π(s1 ) π(s2 ) π(s3 ) ... π(sm )
r-Permutation
An r -permutation of a set S, is an ordered arrangement (sequence) of
r distinct elements of S.
(For this to be well-defined, r needs to be an integer with 0 ≤ r ≤ |S|.)
Examples:
There is only one 0-permutation of any set: the empty sequence ().
For the set S = {1, 2, 3}, the sequence (3, 1) is a 2-permutation.
(3, 2, 1) is both a permutation and 3-permutation of S (since |S| = 3).
There are 6 different different 2-permutations of S. They are:
(f : {1, . . . , r } → S) ∼
= f (1) f (2) f (3) ... f (r )
f : {1, . . . , r } → {1, . . . , n}
n!
P(n, r ) = n · (n − 1) · (n − 2) . . . (n − r + 1) =
(n − r )!
n!
P(n, r ) = n · (n − 1) · (n − 2) . . . (n − r + 1) =
(n − r )!
Proof. There are n different choices for the first element of the
sequence. For each of those choices, there are n − 1 remaining
choices for the second element. For every combination of the first two
choices, there are n − 2 choices for the third element, and so forth.
n! = n · (n − 1) · (n − 2) . . . · 2 · 1 = P(n, n)
Colin Stirling (Informatics) Discrete Mathematics (Chapter 6) Today 20 / 39
Example: a simple counting problem
Solution: We solve this by noting that this number is the same as the
number of permutations of the following six objects:
ABC, D, E, F, G, and H. So the answer is:
6! = 720.
r -Combinations
An r -combination of a set S is an unordered collection of r elements
of S. In other words, it is simply a subset of S of size r .
Theorem
For all integers n ≥ 1, and all integers r such that 0 ≤ r ≤ n:
. n n! n · (n − 1) · . . . · (n − r + 1)
C(n, r ) = = =
r r ! · (n − r )! r!
Theorem
For all integers n ≥ 1, and all integers r such that 0 ≤ r ≤ n:
. n n! n · (n − 1) · . . . · (n − r + 1)
C(n, r ) = = =
r r ! · (n − r )! r!
P(n, r ) n!/(n − r )! n!
C(n, r ) = = =
P(r , r ) r !/(r − r )! r ! · (n − r )!
Colin Stirling (Informatics) Discrete Mathematics (Chapter 6) Today 26 / 39
Combinations: examples
Example:
1 How many different 5-card poker hands can be dealt from a deck
of 52 cards?
2 How many different 47-card poker hands can be dealt from a deck
of 52 cards?
Solutions:
1
52 52! 52 · 51 · 50 · 49 · 48
= = = 2, 598, 960
5 5! · 47! 5·4·3·2·1
2
52 52! 52 · 51 · 50 · 49 · 48
= = = 2, 598, 960
47 47! · 5! 5·4·3·2·1
Theorem
For all integers n ≥ 1, and all integers r , 1 ≤ r ≤ n:
n n
=
r n−r
Theorem
For all integers n ≥ 1, and all integers r , 1 ≤ r ≤ n:
n n
=
r n−r
Proof:
n n! n! n
= = =
r r ! · (n − r )! (n − r )! · (n − (n − r ))! n−r
(x + y )n = (x + y ) · (x + y ) . . . (x + y )
| {z }
n
Example: How many different ways are there to place 12 colored balls
in a bag, when each ball should be either Red, Green, or Blue?
Example
How many different solutions in non-negative integers x1 , x2 , and x3 ,
does the following equation have?
x1 + x2 + x3 = 11
Example
How many different solutions in non-negative integers x1 , x2 , and x3 ,
does the following equation have?
x1 + x2 + x3 = 11
Multinomial Theorem
For all n ≥ 0, and all k ≥ 1:
X
n
(x1 + x2 + . . . + xk ) = n
x1n1 x2n2 . . . xknk
n1 , n2 , . . . , nk
0≤n1 ,n2 ,...,nk ≤n
n1 +n2 +...+nk =n