Permutaions & Combinations
Permutaions & Combinations
CS 2800
Module
Counting
Chapter 5, Rosen
1
Combinatorics
Sum rule: the number of ways that “either task 1 or task 2 can be done,
but not both”, is m + n.
Task 1
Generalizes to multiple tasks ...
Task 2
Example
A student can choose a computer project from one of three lists. The three
lists contain 23, 15, and 19 possible projects respectively. How many
possible projects are there to choose from?
23+15+19
4
Sum rule example
How many strings of 4 decimal digits, have exactly three digits that are 9s?
5
Set Theoretic Version
If A is the set of ways to do task 1, and B the set of ways to do task 2, and
if A and B are disjoint, then:
6
Product Rule
Product rule: the number of ways that “both tasks 1 and 2 can be done” in mn.
8
Product Rule
How many functions are there from set A to set B?
2n
2
How many strings of 4 decimal digits, do not contain the same digit
twice?
We want to chose a digit, then another that is not the same, then
another…
• First digit: 10 possibilities
• Second digit: 9 possibilities (all but first digit)
• Third digit: 8 possibilities
• Fourth digit: 7 possibilities
Total = 10*9*8*7 = 5040
How many strings of 4 decimal digits, end with an even digit?
First three digits have 10 possibilities
Last digit has 5 possibilities
Total = 10*10*10*5 = 5000
11
Set Theoretic Version
12
More complex counting problems
13
Count the number of ways to put things together into various
combinations.
E.g. If a password is 6, 7, or 8 characters long; a character is an
uppercase letters or a digit, and the password is required to include
at least one digit. How many passwords can there be?
“popular” counting trick: let’s calculate all of them, including those with
no digits and then subtract the ones with no digits.
How many possibilities are there if the bride and groom must both be in
the picture
Product rule: place the bride/groom AND then place the rest of the
party
First place the bride and groom
• She can be in one of 6 positions
• He can be in one 5 remaining positions
• Total of 30 possibilities
Next, place the other four people via the product rule
• There are 8 people to choose for the third person, 7 for the fourth, etc.
• Total = 8*7*6*5 = 1680
Product rule yields 30 * 1680 = 50,400 possibilities
18
The inclusion-exclusion principle
(seen briefly when we did sets)
21
Inclusion-exclusion example
How may bit strings of length eight start with 1 or end with 00?
Count bit strings that both start with 1 and end with 00
– Rest of the bits can be anything: 25 = 32
– This is |A1∩ A2|
Once the tree is laid out, the result is the number of (valid) leaves.
24
Tree diagrams example
Use a tree diagram to find the number of bit strings of length four with no three
consecutive 0s
Pigeonhole Principle
12
10+12
10
But you can’t see a thing. How many socks should you get to guarantee a correct
pair? What does it have to do with the pigeon hole principle?
Typical head of hair has around 150,000 hairs. So, it is reasonable to assume
that no one has more than 1,000,000 hairs on their head (m = 1 million
holes).
There are more than 1,000,000 people in NYC (n is bigger than 1 million objects).
If we assign a pigeonhole for each number of hairs on a head, and assign
people to the pigeonhole with their number of hairs on it, there must be at
least two people with the same number of hairs on their heads.
31
Proof of G.P.P.
N N N
k 1 k 1 1 k N
k k k
So, there are less than N objects, which contradicts our assumption of
N objects!
QED
G.P.P. Example
Answer:
280/12 = 23.3 = 24
33
PH principles can be pop up in “all kinds of places”…
Consider 5 distinct points (xi, yi) with integer values, where i = 1, 2, 3, 4, 5.
Show that the midpoint of at least one pair of these five points also has
integer coordinates. (So, 5 points somewhere on a grid. Draw all
connecting line segments. One of the midpoints must be on the grid!)
Thus, we are looking for the midpoint of a segment from (a,b) to (c,d)
– The midpoint is ( (a+c)/2, (b+d)/2 )
Note that the midpoint will be integers if a and c have the same parity: are either
both even or both odd
– Same for b and d
Since we have 5 points, by the pigeonhole principle, there must be two points that
have the same parity!
– Thus, the midpoint of those two points will have integer coordinates.
QED
“The party problem”
Dinner party of six: Either there is a group of 3 who all
know each other, or there is a group of 3 who are all
strangers.
By contradiction. Assume we have a party of six
where no three people all know each other
Let’s say she knows 3 others.
and no three people are all strangers.
If any of those 3 know each other, we
have a blue , which means 3 people
Consider one
know each other. Contradicts
person.
assumption.
So they all must be strangers. But then we
She either knows or doesn’t have three strangers. Contradicts
know each other person. assumption.
R(k,t): N2 -> N is the Ramsey function. R(k,t) is also called the Ramsey number.
Ramsey proved that R(k,t) is well-defined. I.e., for any values of k and t (>= 2),
when the n gets large enough, there will always be a monochromatic Red
complete subgraph of size k or a Blue one of size t.
What are the values of R(k,k)?
R(2,2) = 2
R(3,3) = 6 (shown in 1955)
R(4,4) = 18 (shown in 1955)
R(4,5) = 25 (shown in 1993)
R(5,5) = ? (only recently: 43 <= R(5,5) <= 49)
R(6,6) = ??
42
Permutations
12 11 10 9 8
a) 60
b) 125
c) 12!/7!
d) 512 A.: 12!/7!
e) No clue
43
Combinations
n n!
C ( n, r )
r r !(n r )!
= P(n,r) / r!
Note: we have C(n,r) = C(n, n−r)
45
“n choose r”. Also called a “binomial coefficient”.
Combinatorial proof
Most of the questions in this section are phrased as, “find out how
many possibilities there are if …”
– Instead, we could phrase each question as a theorem:
– “Prove there are x possibilities if …”
– The same answer could be modified to be a combinatorial proof to the
theorem
48
Circular seatings
How many ways are there to sit 6 people around a circular table, where seatings are
considered to be the same if they can be obtained from each other by rotating the
table?
Binomial
Theorem:
Letx and y bevariables,
and let n be any
nonnegative integer. Then
n n j jn
(x y ) x y
n
j
j 0
51
n n j j
n
(x y ) x y
n
j
j 0
What is n? 17
What is j?
17 17 8 9 8 9
9 (3a ) 8
(2b ) 9
3 2 a b
9 9
What is x? 3a
What is y? 2b
Binomial Coefficients
(a + b)2 = a2 + 2ab + b2
(a + b)3 = a3 + 3a2b + 3ab2 + b3
(a + b)4 = a4 + 4a3b + 6a2b2 + 4ab3 + b4
A. 36
B. 220
C. 15
D. 6
E. No clue
A.: 220
n n n j j
(x y ) x y
n
j
j 0
Binomial Coefficients
Powers of 2
Sum each row of Pascal’s Triangle:
n n n Suppose you have a set of size
j 2 n. How many subsets does 2n
j 0
it have?
n n n j j
j 1 1 (1 1)n
j 0
n n n
j 2
j 0
QED
T
S n items
n-1 items
a Pascal’s Identity
A relationship between the entries in Pascal’s triangle.
n n -1 n -1 Suppose T is a set, |T|=n. Let a be an
j j -1 j element in T, and let S = T - {a}. So,
n
|S| = n-1. Let’s count the
j
subsets of size j. Note that
some of these contain a, and
some don’t.
n - 1
How many contain a?
j -1
How many don’t? n - 1
j
56
Vandermonde’s Identity
57
Another combinatorial identity
2
2n r n
n k 0 k
2
2n n n n n n n n
n n k 0 n - k k k 0 k
for the last step we used:
n n
k n - k
And another
n 1 n j
r 1 j r r
x1 x 2 x 3 x 4 10
When the variables are nonnegative integers? 11 locations for
bars. Pick 3 allowing
repetitions.
C(13,3)
1 3 6 0 10
C(n+r-1,r), r-sized combinations
Co
mb Counting paths
ina
tor
ial
A turtle begins at the co upper left corner of an n x m grid and
un
meanders to the lower tinright corner.
gr
eq n = 6
uir
es
pr
ac Need m steps down.
tic
m=4 e. n+1 positions
M
or to go down.
eo
nh
wk
!
How many routes could she take if she only moves right and
down? Hmm…
n 1 m - 1 n m
m m