1 chapter 1 fundamental principles of counting discrete and combinatorial mathematics r. p....

27
1 Chapter 1 Fundamental Principles of Counting Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004

Upload: robyn-little

Post on 13-Jan-2016

337 views

Category:

Documents


15 download

TRANSCRIPT

1

Chapter 1

Fundamental Principles of Counting

Discrete and Combinatorial Mathematics

R. P. Grimaldi, 5th edition, 2004

2

Issues of Counting

How many license plates like AB-1234 are there?

How many 16 digits credit card numbers are there such that they always have at least two different digits?

What is the coefficient of x2y3z4 in the expansion of (x+y+z)9?

Applications: coding theory, probability and statistics, and analysis of algorithms.

3

“ If a first task can be performed in m ways, while a second task can be performed in n ways, and two tasks cannot be performed simultaneously, then performing either task can be accomplished in any one of m+n ways.”

Example: A class has 10 males and 5 females, pickinga student from this class can be done in 10+5=15 ways.

The Rule of Sum

4

The Rule of Product

“ If a procedure can be broken down into two stages, and there are m possible outcomes for the first stage and, for each of these outcomes, there are n possible outcomes for the second stage, then the total procedure can be carried out in mn ways.”

Example: A class has 20 males and 15 females, picking an opposite sex pair from this class can be done in 20×15 = 300 ways.

5

Examples

How many 5-digit sequences are there such that no two consecutive digits are the same?Answer: 109999 = 65610. #

How many 5-digit sequences are there such that no two digits are the same?Answer: 109876 = 30240. #

How many functions f:{1,…,n} {1,…,m}?Answer: mn. #

6

More ExamplesHow many 12 digit credit card numbers are there such that they end with an even number or with “5”?Answer:

Numbers that end with even number: 10115Numbers that end with “5”: 1011

Total: 10115 + 1011 = 600,000,000,000. #

7

Permutations

In how many ways can you ‘line up’ a class of 35 students?Answer: 35×34×33×…×1 ≈ 1.0333148 × 1040,which is the number of permutations of 35 elements. #

In how many ways can you ‘line up’ 20 students from a class of 35 students?Answer: 35×34×…×16 ≈ 7.90192744 × 1027. #

8

Permutations (Cont.)

How many ways can you order n elements?Answer: n(n–1)(n–2)…1 = n!. (say “n factorial”) #

Note: 0!=1, 1!=1, 2!=2, 3!=6, 4!=24, …

How many ways can you order r out of n elements?Answer: n(n–1)(n–2)…(n–r+1) = n! / (n–r)!.Also denoted by P(n,r). #

9

How many 4-letter words out of “desktop”?Answer: P(7,4) = 7!/3! = 840.

How many 4-letter words out of “website”?Answer: Not P(7,4) = 840, because of the two “e”s. 4-letter words with no or one “e”: P(6,4) = 360

(idea: make 4-letter words out of “w e b s i t”)4-letter words with two “e”s: 6 × P(5,2) = 120

(idea: positions of two “e”s gives 6 possibilities,the remaining two letter positions can be completedin P(5,2) = 20 ways from “w b s i t”.)

Total: 360+120 = 480. #

Examples

10

Permutations with Repetitions How many ways can you select r out of n positions?We just saw that n=4 and r=2 gives 6 possibilities: , , , , , .

One way of re-phrasing it: “How many strings of length n can you make out of r symbols and n–r symbols ?”(This is not n! because many symbols are identical.)

Another way of phrasing it: “How many ways can you select r different numbers (=positions) out of {1,2,…,n}?(This is not P(n,r) because the order of choosing does not matter; e.g. picking 3,4 versus picking 4,3.)

11

Answer 1How many n-strings can you make of r “” and n–r “”?

The answer would be n! if all and would be unique.Example for n=4 and r=2: Consider: , , , for whichthere are indeed 4!=24 combinations:

, , , , ,

, , , , ,

, , , , , , , , , ,

Indeed 24/4=6.

12

Answer 1 (cont.)

If all and are unique, the answer is n! Dividing this number by the factor of overcounts gives the right answer.

The r symbols “” give an overcount factor of r!.The n–r symbols “” give an overcount factor of (n–r)!.

Hence the right answer is: .!r)!rn(

!n)r,n(C

13

Answer 2How many ways can you select r numbers out of 1,2,…,n? This is not P(n,r) as the order of choosing does not matter.

Example for n=4, r=2: The P(4,2) = 12 ways of selecting two different numbers out of {1,…,4} are: (1,2), (2,1),(1,3), (3,1), (1,4), (4,1), (2,3), (3,2), (2,4), (4,2), (3,4), (4,3).

The overcount factor is 2; the right answer is P(4,2)/2 = 6.

In general, the overcount factor will be r!,

hence we have again: .!r)!rn(

!n

!r

)r,n(P)r,n(C

14

ExampleHow many routes are there from the lower-left corner to the upper-right corner of an mn grid in which we restricted totraveling only to the right or upward?

Answer: . #

!!

)!(

nm

nm

15

Combinations

How many ways can you select r objects out of n?(without concern for the order of selection)

Answer:

.!)!(

!

!

),(),(

rrn

n

r

rnP

r

nrnC

Say: “n choose r”.

Despite the fraction, C(n,r) will always be an integer.

16

Combinations

Also:

n

n1

!n!0

!n

0

n

1n

nn

)!1n(!1

!n

1

n

2n

n)1n(n

)!2n(!2

!n

2

n21

Because: we have )!rn(!r

!n

r

n

rn

n

r

n

17

SummationsThe sum of a list of n+1 terms like am, am+1, …, am+n, where m and n are integers and n0, is denoted by Sigma notation as

lower limit: m upper limit: m+n index: i

....1 nmmm

nm

mii aaaa

18

Properties of Summations

.2

)1(

11

nnji

n

j

n

i

.6

)12)(1(...21 222

0

2

1

2

nnnnii

n

i

n

i

.2

)1(3)...21(333

01

nnnii

n

i

n

i

.22...22222

31

nn

i

n

i

19

Binomial Theorem

Proof.Consider (x+y)n = (x+y)(x+y)…(x+y) with n factors.

The coefficient of xkyn-k, where 0 k n, is the number of different ways in which we select k x’s from n factors.

The total number of such selections is C(n,k). #

If x an y are variables and n is a positive integer, then

n

k

knknnnnn yxk

nyx

n

nyx

nyx

nyx

nyx

0

022110 .210

)(

20

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

Pascal’s Triangle

21

Corollary

n

k k

nnnCnCnC

0

),()1,()0,( •

n

k

kn

k

nnnCnCnCnC

0

)1(),()1()2,()1,()0,(

.2)11(110

nnn

k

kkn

k

n

.0)11()1(10

nn

k

kkn

k

n

22

More CombinationsQ: How many 11-letter words out of “M i s s i s s i p p i”?

Answer: There is one “m”, four “i”, four “s”, and two “p”;calculate the answer by positioning the letters by type:

We can position the “m” in 11 ways (leaving 10 spots open),we can position the four “i” in C(10,4) ways, (6 spots open), we can position the four “s” in C(6,4) ways, (2 spots open), and we can position the two “p” in C(2,2) ways.

Overall answer: C(11,1)×C(10,4)×C(6,4)×C(2,2) = 34650.

Note, this equals: 11!/(1! 4! 4! 2!) = 34650.

How to generalize?

23

Multinomial TheoremFor positive integers n, t, the coefficient of

in the expansion of (x1+x2+…+xt)n is

where each ni is an integer with 0nin, for all 1 i t, and n1 + n2+…+nt = n.

tnt

nn xxx 2121

!!!

!

21 tnnn

n

Proof.The coefficient of is the number of ways in which we select x1 from n1 of the n

factors, x2 from n2 of the n-n1 factors, …, xt from nt of the n - n1 – n2 - … - nt-1 = nt factors.

The total number of such selections is

tnt

nn xxx 2121

t

t

n

nnn

n

nn

n

n 11

2

1

1

.!!!

!

21 tnnn

n

#

24

Question: How many alphabetized strings are there of length 3 containing the letters a,b,c?

Brute force answer: 10, namely: aaa, aab, aac, abb, abc, acc, bbb, bbc, bcc, and ccc. Slightly less brute force: Alphabetization: the only thing that matters is the multitude of the letters a,b,c.Introduce the 3 nonnegative counters na nb and nc.

How many combinations are there such that na+nb+nc=3?

Answer is 10: (3,0,0) (2,1,0) … (0,0,3).Another way of visualizing these 10 options is: = (3,0,0) and = (2,1,0) … and = (1,1,1) … and = (0,0,3).Answer: C(5,2) = 10

Combinations with Repetitions

25

Combinations with RepetitionsConsider a list of k words, out of a dictionary of n words.

How many different, alphabetized lists are possible?

Answer: Let the 1st word occurs k1 times, the 2nd word occurs k2 times,…, the nth word kn times.

How many different sums k1+…+kn = k are there?

Consider k symbols “” with n–1 separators “”, suchthat 3+0+2=5 is represented by “” (k=5, n=3).

For given n and k, there are C(n+k–1,k) possibilities.

26

SummaryWhen counting the number if selections of k elements out of 1,…,n, consider two crucial questions:

Repetition: Can an element be picked more than once? Order: Is the order of picking relevant?

Ord

eri

ngre

leva

nt?

Repetition allowed?

yes no

yes nk (Arrangement)

P(n,k) (Permutation)

no C(n+k-1,k) (Combinations

with repetitions)

C(n,k) (Combinations)

27

Brainstorm

騎士在旅途中遇見三位美女,其中有天使也有魔鬼。天使向來只說真話,而魔鬼總是說謊。三位美女 A,B,C 的對話如下 :

A: B 和 C 之中,至少有一位是天使。 B: A 和 C 之中,至少有一位是魔鬼。 C: 我來告訴你正確的道路。 問題:有幾位天使?