Anda di halaman 1dari 41

R.

Johnsonbaugh
Discrete Mathematics
5
th
edition, 2001
Chapter 4
Counting methods
and the pigeonhole principle
4.1 Basic principles
Multiplication principle
If an activity can be performed in k
successive steps,
Step 1 can be done in n
1
ways
Step 2 can be done in n
2
ways

Step k can be done in n
k
ways
Then: the number of different ways that the
activity can be performed is the product
n
1
n
2
n
k
Examples-1
Consider a restaurant menu that has the
following items on it:

2 appetizers (Nachos, Salad)
3 main courses (Hamburger, Falafel, Fish)
4 beverages (Tea, Coffee, Sprite, Apple)

How many dinners consist of one appetizer and
one main course?

How many dinners consist of one main course
and an optional drink?

Example-1
Consider a restaurant menu that has the
following items on it:

2 appetizers (Nachos, Salad)
3 main courses (Hamburger, Falafel, Spaghetti)
4 beverages (Tea, Coffee, Sprite, Apple, None)

How many dinners consist of one appetizer and
one main course? (NH, NF, NS, SH, SF, SS)

How many dinners consist of one main course
and an optional drink? 15

Example-2
In expensive digital cameras, an amount of light
could be encoded as 24-bit strings for visual
display. How many values are then possible on
each pixel?






How many 24-bit strings begin with the
substring 10101?

Example-2
In expensive digital cameras, an amount of light
could be encoded as 24-bit strings for visual
display. How many values are then possible on
each pixel?

There are 24 positions, each position can assume
one of 2 values (0 or 1). Then, there are 2222 =
2
24
= 16777216

How many 24-bit strings begin with the
substring 10101?

There are 19 positions left now. This is 2
19

Addition principle
Let X
1
, X
2
,, X
k
be a collection of k
pairwise disjoint sets, each of which has n
j

elements, 1 < j < k, then the union of
those sets

k
X = X
j

j =1
has n
1
+ n
2
+ + n
k
elements
Example-3
In how many ways can we select two
books from different subjects among five
distinct CS books, three distinct Math
books, and two distinct art books?

Example-3
In how many ways can we select two
books from different subjects among five
distinct CS books, three distinct Math
books, and two distinct art books?

We can select from CS and Math in 5x3=15
We can select from CS and Arts in 5x2=10
We can select from Math and Arts in 3x2=6
Since these sets of selections are pairwise
disjoint, we use addition principle to get
15+10+6=31 ways to get our selection

4.2 Permutations and combinations
A permutation of n distinct elements x
1
, x
2
,, x
n

is an ordering of the n elements. There are n!
permutations of n elements.

Example: there are 3! = 6 permutations of three
elements a, b, c:
abc bac cab
acb bca cba
Example-4
In how many ways can we select a chairperson, vice chairperson,
secretary, and treasurer from a group of 12 persons?
Example-4
In how many ways can we select a chairperson, vice chairperson,
secretary, and treasurer from a group of 12 persons?

There are 12 ways of choosing the chairperson
There are 11 ways of choosing the vice chairperson
There are 10 ways of choosing the secretary
There are 9 ways of choosing the treasurer

Therefore, there are 12x11x10x9 permutations of selecting the team

This gives rise to the following theorem

r-permutations
An r-permutation of n distinct elements is an ordering
of an r-element subset of the n elements x
1
, x
2
,, x
n

Theorem 4.2.10:
For r < n the number of r-permutations of a set with n
distinct objects is

P(n,r) = n(n-1)(n-2)(n-r+1)
= n(n-1)(n-2)(n-r+1)(n-r)2.1/(n-r)2.1
= n! / (n 1)!


Example-5
How many permutations of the letters ABCDEF
contain the letters BCF together in any order?

Example-5
How many permutations of the letters ABCDEF
contain the letters BCF together in any order?


Consider them as one unit, call it U
Then we have ADEU
There are 4! permutations for ADEU
There are 3! permutations for selecting and arranging U


There are then 4! x 3! = 24 x 6 = 144 permutations


Example-6
In how many ways can we seat
4 persons in one row across a
straight table?





In how many ways can we seat
4 persons around a circular
table?


A B
C
D
A B C D
Example-6
In how many ways can we seat
4 persons in one row across a
straight table? Since there are
n ways of selecting the nth
person, there are n! ways

In how many ways can we seat
4 persons around a circular
table? Likewise, however, if a
seating is obtained from
another seating by having
everyone move n seats, the
seatings are considered
identical. Therefore, its n!/n,
or, (n-1)!


A B C D
A B
C
D
Combinations
Let X = {x
1
, x
2
,, x
n
} be a set containing n
distinct elements
An r-combination of X is an unordered selection of
r elements of X, for r < n
The number of r-combinations of X is the binomial
coefficient

C(n,r) = =n! / r!(n-r)! = P(n,r)/ r!
|
|
.
|

\
|
r
n
Example-7
In how many ways can we select a committee of 4
from a group of 9 persons?

Example-7
In how many ways can we select a committee of 4
from a group of 9 persons?


Since the committee is an unordered group of people, the
answer is



126
! 4
6 7 8 9
)! 4 9 ( ! 4
! 9
4
9
=

=

=
|
|
.
|

\
|
Careful Now!
Get the difference between permutations and
combinations?

Permutations: order does matters
Combinations: order does not matter

Example.

How many permutations to select 2 letters from A, B, C, D?

How many combinations to select 2 letters from A, B, C, D?

Careful Now!
Example.

How many permutations to select 2 letters from A, B, C, D?
There are P(4,2) = 4!/2! = 4 x 3 = 12. They are:
AB, AC, AD, BA, BC, BD, CA, CB, CD, DA, DB, DC
Note here how order matters. For example, AB is not BA

How many combinations to select 2 letters from A, B, C, D?
There are C(4,2) = 4!/2! 2! = 3 x 2 = 6. They are:
AB, AC, AD, BA, BC, BD, CA, CB, CD, DA, DB, DC

Crossed combinations are eliminated because they are a repeat. So:

AB, AC, AD, BC, BD, CD

Catalan numbers
Eugene-Charles Catalan (1814-1894)
Catalan numbers are defined by the formula
C
n
= C(2n,n) / (n+1)
for n = 0, 1, 2,
The first few terms are:




Appears in analysis, combinatorics, algebra, number
theory, probability,

n 0 1 2 3 4 5 6 7 8 9 10
C
n
1 1 2 5 14 42 132 429 1430 4862 16796
4.3 Algorithms for generating
permutations and combinations
A group has recorded n videos whose running times
are t
1
, t
2
,t
n
seconds.
A tape is to be released that can hold C seconds
The problem is to maximize the number of recordings
and minimize time on tape left unused
Using set notation, the problem is to choose a subset
{i
1
, i
2
,i
k
} of {1, 2, , n} such that the sum



does not exceed C and is a large as possible

=
k
j
i
j
t
1
4.3 Algorithms
A straightforward approach is to examine all subsets
of {1, 2, , n} and choose the best subset
We then need an algorithm that generates all
combinations of an n-element set
Since there are 2
n
subsets of an n-element set, the
running time that examines such subsets is O(2
n
)
Such exponential running time algorithms are
impractical for large values of n
Unfortunately for such algorithms, there are no short-
cut ways to avoid such combinatorial generation
This problem is also know as the knapsack problem
Algorithms Rules
Algorithms should list permutations and combinations in
lexicographical order

Lexicographic order: a generalization of ordinary dictionary order
by replacing alphabet by any set of symbols on which as order
has been defined

Given two distinct words, we determine precedence by
comparing the letters in the words as follows

If the words have different lengths, and each letter in the shorter
word is identical to the corresponding letter in the longer world, then
the shorter word precedes the longer

If the words have the same or different lengths, we then locate the
leftmost position p at which the letters differ. The order is then easily
determined by based on the character values
Example
Mathematically, this is how we determine the
precedence of two distinct words
Given two strings o = s
1
s
2
s
p
and | = t
1
t
2
t
q
Define o < | if
p <= q and s
i
= t
i
for all i = 1, 2,, p
Or for some i, s
i
= t
i
and for the smallest i, s
i
< t
i


Example: if o = 1324, | = 1332, = 132,
then < o and o < |.
Generating Algorithms
Consider the problem of listing all r-
combinations of {1,2,,n}. How would you
device an algorithm to generate such
combinations in lexicographical order? An
order such that the first string will be 12n,
and the last string will be (n-r+1)n?
Example
Consider the order in which the 5-combination
of {1,2,3,4,5,6,7} will be listed. List the first
seven combinations and the last one in
lexicographical order:

The first is 12345

Example
Consider the order in which the 5-combination of
{1,2,3,4,5,6,7} will be listed. List the first seven
combinations and the last one in lexicographical
order:

The first is 12345
The second is 12346
The third is 12347
The forth is 12356
The fifth is 12357
The sixth is 12367
The seventh is 12456
The last is 34567
4.6 Generalized permutations
and combinations
Theorem 4.6.2: Suppose that a sequence of n
items has n
j
identical objects of type j,
for 1< j < k. Then the number of orderings of S
is
____n!____
n
1
!n
2
!...n
k
!
Example
How many strings can be formed using the following letters

M I S S I S S I P P I ?

Because of the duplication of letters, we cant just say 11! and get it
over with.

There are C(11,2) ways to choose positions for the Ps
There are C(9,4) ways to choose positions for the Is
There are C(5,4) ways to choose positions for the Ss
There is one position left to be filled by the M
By the multiplication principle, the number of ways of ordering the letters
is:

C(11,2)C(9,4)C(5,4)= 11! 9! 5! = 34,650
2! 9! 4! 5! 4!
The Algorithms

Lets take a brief look at the two algorithms
on their transparencies

Combinations generating algorithm

Permutations generating algorithm
4.7 Binomial coefficients
and combinatorial identities
Theorem 4.7.1: Binomial theorem. For any real
numbers a, b, and a nonnegative integer n:
(a+b)
n
= C(n,0)a
n
b
0
+ C(n,1)a
n-1
b
1
+
+ C(n,n-1)a
1
b
n-1
+ C(n,n)a
0
b
n

Examples
n=1: a+b
n=2: a
2
+2ab+b
2

n=3: a
3
+3a
2
b+3ab
2
+b
3

4.7 Binomial coefficients
and combinatorial identities
Theorem 4.7.6: For 1 < k < n,
C(n+1,k) = C(n,k) + C(n,k-1)
This comes in handy when you already know the
value of the binomial coefficient for a smaller set
Example: Assume you have all computations
performed for C(5,i), i=1..5, then, what is C(6,4)?
C(6,4)=C(5,4)+C(5,3)=5+10=15
Pascals Triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

4.8 The pigeonhole principle
First form: If k < n and n pigeons fly into k
pigeonholes, some pigeonhole contains at least
two pigeons.
Second form of the
pigeonhole principle
If X and Y are finite sets with |X| > |Y| and
f : X Y is a function, then f(x
1
) = f(x
2
) for
some x
1
, x
2
e X, x
1
= x
2
.

Third form of the
pigeonhole principle
If X and Y are finite sets with |X| = n, |Y| = m
and k = n/m(, then there are at least k values
a
1
, a
2
,, a
k
e X such that f(a
1
) = f(a
2
) = f(a
k
).

Example:
n = 5, m = 3
k = n/m( = 5/3( = 2.
Examples
Ten persons have three color for pants to
choose from and three colors for shirts. Show
that at least two persons will come out wearing
the same combination.
Example
Ten persons have three color for pants to choose from and three colors for
shirts. Show that at least two persons will come out wearing the same
combination.


We can see that there are 9 combinations for the 10 persons

If we think of persons as pigeons and colors as pigeonholes, we can consider
the assignment of persons to colors to be that of assigning pigeonholes to the
pigeons. By the Pigeonhole principle, some color pair (pigeonhole) is assigned
to at least two persons (pigeons)

So, if the pants are red, green, and blue and the shirts are cyan, magenta, and
yellow, then we have:

RC, RM, RY, GC, GM, GY, BC, BM, BY. These are nine, how about the tenth? You
must repeat.

Anda mungkin juga menyukai