0% found this document useful (0 votes)
62 views50 pages

Permutaions & Combinations

This document discusses counting techniques in discrete mathematics including the sum rule, product rule, and inclusion-exclusion principle. The sum rule states that the number of ways to do task 1 or task 2 is the sum of the number of ways to do each task individually. The product rule states that the number of ways to do both tasks 1 and 2 is the product of the number of ways to do each task. Examples are provided to illustrate these rules. The inclusion-exclusion principle is introduced as a way to avoid double counting when calculating possibilities involving sets.

Uploaded by

Dr.A.Gayathri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views50 pages

Permutaions & Combinations

This document discusses counting techniques in discrete mathematics including the sum rule, product rule, and inclusion-exclusion principle. The sum rule states that the number of ways to do task 1 or task 2 is the sum of the number of ways to do each task individually. The product rule states that the number of ways to do both tasks 1 and 2 is the product of the number of ways to do each task. Examples are provided to illustrate these rules. The inclusion-exclusion principle is introduced as a way to avoid double counting when calculating possibilities involving sets.

Uploaded by

Dr.A.Gayathri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

Discrete Math

CS 2800

Prof. Bart Selman


[email protected]

Module
Counting
Chapter 5, Rosen
1
Combinatorics

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?
Or, how many graphs are there on N nodes? How many of those are
3-colorable?

Many uses in discrete math (because of all the discrete strucures),


including e.g. probability theory (next topic).
E.g., what is the probability that a randomly generated graph is 3-
colorable?
How can we figure that out?
First, two most basic rules:
– Sum rule
– Product rule
Sum Rule

Let us consider two tasks:


– m is the number of ways to do task 1
– n is the number of ways to do task 2
– Tasks are independent of each other, i.e.,
• Performing task 1 does not accomplish task 2 and vice versa.

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 

Ok… not to worry. things will get more exciting!

4
Sum rule example

How many strings of 4 decimal digits, have exactly three digits that are 9s?

– The string can have:


• The non-9 as the first digit
• OR the non-9 as the second digit
• OR the non-9 as the third digit
• OR the non-9 as the fourth digit
• Thus, we use the sum rule
– For each of those cases, there are 9 possibilities for the non-9 digit (any number
other than 9)
– Thus, the answer is 9+9+9+9 = 36

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:

“the ways to do either task 1 or 2 are


AB, and |AB| = |A| + |B|”

6
Product Rule

Let us consider two tasks:


– m is the number of ways to do task 1
– n is the number of ways to do task 2
– Tasks are independent of each other, i.e.,
• Performing task 1does not accomplish task 2 and vice versa.

Product rule: the number of ways that “both tasks 1 and 2 can be done” in mn.

Generalizes to multiple tasks ...


task 1 task 2
Product rule example

– There are 18 math majors and 325 CS majors


– How many ways are there to pick one math major and one CS major?

Total is 18 * 325 = 5850

8
Product Rule
How many functions are there from set A to set B?

So, how many Boolean


A B functions on n vars?

2n
2

To define each function we have to make 3 choices, one for each


element of A. Each has 4 options (to select an element from B).
How many ways can each choice
4 be made?
4 4

43= 64 = |B| |A|


# is called P(n,r) for r-permutations Why does order
(here P(4,3) --- “3 unique choices out of 4 matter in this example?
objects”, order matters)
How many one-to-one functions are there from set A to set B?

B Ex: S={1,2,3}. Ordered arrangement


A
3,1,2 is called a permutation.
There are n! of those (product rule).
3,2 is a r-permutation (r=2).
There are n!/(n-r)! of those.
I.e., n x (n-1) x (n-1) x … x (n-r+1)
To define each function we have to make 3 choices, one for each
element of A.
How many ways can each choice
2 be made?
4 3
24 = 4! / (4-3)!
Hmm. What if |A| = 4?
Product rule example

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

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

The ways to do both task 1 and 2 can be represented as AB,


and |AB|=|A|·|B|

12
More complex counting problems

Combining the product rule and the sum rule.

Thus we can solve more interesting and complex 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?

Let P – total number of possible passwords


Pi – total number of passwords of length i, i = 6,7,8
P = P6 + P7 + P8 (sum rule)

Pi – computing it directly is tricky (hmm…) How??

“popular” counting trick: let’s calculate all of them, including those with
no digits and then subtract the ones with no digits.

Pi= 36i – 26i

P = 366 – 266+ 367 – 267 + 368 – 268 = 2,684,483,063,360


Wedding pictures example
#1
Consider a wedding picture of 6 people
– There are 10 people, including the bride and groom

How many possibilities are there if the bride must be in the


picture?
Product rule: place the bride AND then place the rest of the party
First place the bride
• She can be in one of 6 positions
Next, place the other five people via the product rule
• There are 9 people to choose for the second person, 8 for the third, etc.
• Total = 9*8*7*6*5 = 15120
Product rule yields 6 * 15120 = 90,720 possibilities

Q.: Are we counting same subsets of folks in different positions?


Yes! (note bride is treated “differently”; has to be in; draw diagram)
17
Wedding pictures example
#2
Consider a wedding picture of 6 people
– There are 10 people, including the bride and groom

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)

When counting the possibilities, we can’t include a given


outcome more than once.

|A1U A2| = |A1| + |A2| - |A1∩ A2|

– E.g. Let A1 have 5 elements, A2 have 3 elements, and 1 element be


both in A1 and A2
– Total in the union is 5+3-1 = 7, not 8

21
Inclusion-exclusion example
How may bit strings of length eight start with 1 or end with 00?

Count bit strings that start with 1


– Rest of bits can be anything: 27 = 128
– This is |A1|

Count bit strings that end with 00


– Rest of bits can be anything: 26 = 64
– This is |A2|

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|

Use formula |A1U A2| = |A1| + |A2| - |A1∩ A2|

Total is 128 + 64 – 32 = 160


Tree diagrams

We can use tree diagrams to enumerate the possible choices.

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

If k+1 objects are assigned to k places,


then at least 1 place must be assigned ≥2 objects.

Proof: (by contradiction; does this require a proof?)


Suppose none of the k places contains more than one object. Then the total
number of objects would be at most k. This is a contradiction, since there
are k + 1 objects. QED 

In terms of the assignment function:


If f: A→B and |A|≥|B|+1, then some element of B
has ≥2 pre-images under f. I.e., f is not one-to-one.
More pigeons than pigeonholes
Example

How many students must be in class to guarantee that at


least two students receive the same score on the final
exam, if the exam is graded on a scale from 0 to 100
points?
102

So, if a million students take a national test with say 100


questions, many must have the same score (in expectation
10,000). So, would need at least a million questions to get a chance of a
unique score for everyone. Unless… ???
Simple Example
It’s dark; you know that in your drawer there are:

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?

1 hole per color


A.: 3
There must be at least two people in New York city with exactly
the same number of hairs on their heads. Why?

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.

Useful stuff to know… 


Generalized Pigeonhole Principle

If N≥k+1 objects are assigned to k places, then at


least one place must be assigned at least N/k
objects.
E.g., there are N = 280 people in a party. There are k = 52
weeks in the year.
– Therefore, there must be at least 1 week during which
at least 280/52 = 5.38 = 6 students in the party
have a birthday.

31
Proof of G.P.P.

By contradiction. Suppose every place has < N/k objects,


thus ≤ N/k−1.
Then the total number of objects is at most

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

Given: There are 280 people in the party. Without knowing


anybody’s birthday, what is the largest value of n for which we
can prove that at least n people must have been born in the same
month?

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

There are four parity possibilities


– (even, even), (even, odd), (odd, even), (odd, odd)

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.

The case where she doesn’t know 3


But there are 5 other people! others is similar. Also, leads
So, she knows, or doesn’t to constradiction.
know, at least 3 others.
So, such a party does not exist!
(GPH) QED
Party problem: Nicer in terms of graphs.
Consider the complete graph on N = 6 nodes.

Now color each edge either blue (“know each other”) or


red (“don’t know each other”).
It follows that each coloring will contain a red or a blue triangle,
no matter how the graph is colored!
Proof handles:
215 = 32,768
possible edge colorings.
A blue or red (or both)
triangle is always present.
Removing “symmetries”:
78 cases remain.

Example of a Ramsey theory: hidden structure in (random) graphs!


What about a party of five? No red or
blue triangle!
So, property does
not hold for party
of five.
Define: Let R(k,t) be the minimal n such that if the edges of the complete
graph on n nodes are colored Red and Blue, then there either is a
complete subgraph of k nodes with all edges Red or a complete subgraph
of t nodes with all edges Blue.

R(k,t): N2 -> N is the Ramsey function. R(k,t) is also called the Ramsey number.

What is K(3,3)? K(3,3) = 6

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) = ??

Problem becomes surprisingly difficult, very quickly!


Note: N nodes, 2O(N2) colorings. N = 10, gives > ~1030; N=30, gives >~10135
Paul Erdös (most productive contemporary mathematician):

"Imagine an alien force, vastly more powerful than us landing on Earth


and demanding the value of R(5, 5) or they will destroy our planet.” [hmm?]
In that case, we should marshal all our computers and all our mathematicians
and attempt to find the value. …
But suppose, instead, that they asked for R(6, 6),
then we should attempt to destroy the aliens". 

Hmm. Or hire some more computer scientists! ... (Selman ’08) 


Aside: Can extend to 3 colorings etc.

The only two 3-colorings of


the complete graph on 16
nodes, that has no monochromatic
triangles.
Permutations

A permutation of a set S of objects is an ordered arrangement of the elements of


S where each element appears only once:
e.g., 1 2 3, 2 1 3, 3 1 2
There are n! permutations of n objects. (by product rule)

An ordered arrangement of r distinct elements of S is called an r-permutation.

The number of r-permutations of a set S with n=|S| elements is

P(n, r) = n(n−1)…(n−r+1) = n! / (n−r)!

42
Permutations

In a running race of 12 sprinters, each of the top 5 finishers


receives a different medal. How many ways are there to
award the 5 medals?

12 11 10 9 8
a) 60
b) 125
c) 12!/7!
d) 512 A.: 12!/7!
e) No clue

43
Combinations

The number of ways of choosing r elements from S (order does not


matter).
S={1,2,3}
e.g., 1 2 , 1 3, 2 3

The number of r-combinations C(n,r) of a set with n=|S| elements is

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

A combinatorial proof is a proof that uses counting arguments to


prove a theorem.
– Rather than some other method such as algebraic techniques

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?

First, place the first person in the north-most chair


– Only one possibility
(why can we restrict ourselves to only one specific person in that chair?)
Then place the other 5 people
– There are P(5,5) = 5! = 120 ways to do that
any more issues with rotating table?
no!
By the product rule, we get 1*120 =120

Alternative means to answer this:


There are P(6,6) = 720 ways to seat the 6 people around the table
For each seating, there are 6 “rotations” of the seating
Thus, the final answer is 720/6 = 120
Binomial Coefficients

(a + b)4 = (a + b)(a + b)(a + b)(a + b)


4  4  4  4  4 
=0a4 +1 a3b +2a2b2 +3 ab3 +4 b4

Binomial
 Theorem:
 Letx and y bevariables,
 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 the coefficient of a8b9 in the expansion of (3a +2b)17?




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

Pascal’s triangle What is coefficient


of a9b3 in (a + b)12?

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?

How many subsets of size 0


 does it have?
n C0
How many subsets of size 1
does it have?
n C1
How many subsets of size 2
does it have?
n C2

Add them up we have the result. QED


n n  n
j  2
j 0  

Alternative (clever) proof? Look at binomial theorem…



n n  n  j j x and y are variables; can pick
(x  y )   x y
n
any numbers… hmm…
j
j 0  

Pick x=1 and y=1 !

 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

Let m, n, and r be nonnegative integers with r not


exceeding either m or n. Then

m n r  m n


     Why?
 r  j0 r - jj

To choose r items, take some


A B
[(r-j)] from A and some [j]
m
items n items from B. All possible ways
of doing this gives the
result. (note: items should
all be distinct.)

57
Another combinatorial identity

2
 2n  r  n 
     
 n  k 0  k 

Follows directly from the Vandermonde’s identity with m = r = n:

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 

Proof. See thm. 4, section 5.4


Combinations with repetition
There are C(n+r-1,r), r-sized combinations from a set of n
elements when repetition is allowed.
Proof. See thm. 2, section 5.5.

Example: How many solutions are there to the equation

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 

You might also like