Fundamental Principles of Counting1 From Chapter 1 of Discrete and Combinatorial Mathematics, 4 th...

67
Fundamental Principles of Counting 1 Fundamental Principles of Counting From Chapter 1 of Discrete and Combin atorial Mathematics, 4 th ed, by R. P. Grimaldi

Transcript of Fundamental Principles of Counting1 From Chapter 1 of Discrete and Combinatorial Mathematics, 4 th...

Fundamental Principles of Counting 1

Fundamental Principles of Counting

From Chapter 1 of Discrete and Combinatorial Mathematics, 4th ed, by R. P. Grimaldi

Fundamental Principles of Counting 2

Outline

• The Rules of Sum and Product• Permutations• Combinations: The Binormial Theorem• Combination with Repetition• An Application in the Physical Sciences (*)• The Catalan Number (*)• Summary and Historical Review

Fundamental Principles of Counting 3

Introduction

• Enumeration does not end up with arithmetic.• 枚舉 (enumeration ) 或計算 (counting)

• It also has applications in such areas as coding theory, probability and statistics, and in the analysis of algorithms.

• Be sure to learn and understand the basic formulas -- but do not rely on them to heavily.

• For without an analysis of each problem, a mere knowledge of formulas is next to useless.

Fundamental Principles of Counting 4

1.1 The Rules of Sum and Product

• In analyzing more complicated problems, one is often able to break down such problems into parts that can be solved using these basic problem.

• We want to develop the ability to “decompose” such problems and piece together our partial solutions in order to arrive at the final answer.

• The Rule of Sum: If a first task can be be performed in m ways, while a second task can be performed in n ways, and the two task can be performed simultaneously, then performing either task can be accomplished in any one of m+n ways.

Fundamental Principles of Counting 5

• 例 1: 一所大學圖書館有 40 冊有關社會學教科書,以及 50 冊有關人類學教科書,根據和法則,一個學生欲求得有關這兩門課程中的任何一門的更多的知識則可自 40+50=90 冊書中選擇任何一冊。

• 例 2: 上述法則可推廣至兩件工作以上,但其中不能有任何兩件同時進行。例如,一位電子計算機教師對於APL 、 BASIC 、 FORTRAN 、以及 Pascal 各有五冊初級課本,則此教師可從此 20 冊中任選一冊給一個想開始學程式語言的學生。

1.1 The Rules of Sum and Product

Fundamental Principles of Counting 6

Example

• 例 3 設前例中電子計算機教師有兩位同事,其中一位有演算法分析教本三冊,另一位有這樣的教本五冊。若 n 表此教師可借的冊數,則 5≦n≦8 ,因為這兩位同事持有的教本可能相同。

Fundamental Principles of Counting 7

Example:

• 例 4: 設一工廠欲評估是否必須增加生產線,主管指派 12 位僱員分別組成兩個委員會。 A 委員包括 5 位成員,其任務為調查在這項發展目標可能約有利﹒結果。另外 B 委員會中的 7 人則詳察可能不利的影響。若此主管在他下決心之前打算僅告知一個委員的人員,則由和法則,得知共有 12 位僱員可被他請來告知。但是為了公平起見,在他末下決心前,他決定在星期一告知 A 委員會中的一位人員,然後在星期二告知 B 委員會中的一位人員。利用下述原理,我們發現這位主管可告知兩位這樣的人員,其力法有 5x7=35 種。

Fundamental Principles of Counting 8

• Example 1.1: 40 textbooks on sociology and 50 textbooks on anthropology

• Example 1.2: Five introductory books each on C++, FORTRAN, Java, and Pascal

• Example 1.3: Two colleagues, one has three textbook on the analysis of algorithms, and the other has five. 5≦n≦8 , n denotes the maximum number of different books on this topic that an instructor can borrow.

Fundamental Principles of Counting 9

1.1 The Rules of Sum and Product• Example 1.4:

Committee A5

Committee B7

12 employees

Should the administrator decide to speak to just one committee member before making her decision, then 12 employee she can call upon for input.

A member of Committee A on Monday, a member of Committee B on Tuesday, then .75

Fundamental Principles of Counting 10

1.1 The Rules of Sum and Product

• The Rule of Product:

If a procedure can be broken down into first and seco

nd stages, and if there are m possible outcomes for t

he first stage and if, for each of these outcomes, ther

e are n possible outcomes for the second stage, then

the total procedure can be carried out, in the designat

ed order, in mn, ways.

Fundamental Principles of Counting 11

1.1 The Rules of Sum and Product

• Example 1.6: License plate (車牌) consisting of two letters followed by four digits– No letter or digit can be repeated: 262510987= 327

60– With repetitions of letters and digits allowed: 26261010

1010=6760000

• Example 1.7: • Computer Memory

– 1-byte address: 22222222 =256 – 2-byte address: 256256=65536 available addresses– 32-bite architecture: 28282828=4,294,967,296– 8-byte

Fundamental Principles of Counting 12

1.1 The Rules of Sum and Product

• Example 1.8: Six kinds of muffins( 鬆餅 ), eight kinds of sandwiches, and five beverages (hot coffee, hot tea,iced tea, cola, and orange juice). Want a lunch either a muffin and a hot beverage or a sandwich and a cold beverage.– There are 62 83=36 ways

Fundamental Principles of Counting 13

1.2 Permutations (排列)• Permutations

– Counting linear arrangements of objects

• We shall develop some systematic methods for dealing with linear arrangements.

Fundamental Principles of Counting 14

1.2 Permutations

• Example 1.9: In a class of 10 students, five are to be chosen and seated in a row for a picture. How many such linear arrangements are possible?

10 9 8 7 6 = 30,240

5!

10!

Fundamental Principles of Counting 15

1.2 Permutations• Definition 1.1 For an integer n≥0, n factorial (denoted n!) is

defined by 0!=1, n!=n(n-1)(n-2)...(3)(2)(1), for n ≥1.

• How fast the value of n! increase?– 10!=3628800,– 11! exceeds the number of seconds in one year,– 12! exceeds the number in 12 years, – 13! surpasses the number of seconds in a century.

Fundamental Principles of Counting 16

Definition• Definition 1.1: Given a collection of n distinct objects,

any (linear) arrangements of these objects is called a permutation of the collection.

• In general, if there are n distinct objects, the number of permutations of size r for the n objects is

)!(

!

)1)(2)(3()(

)1)(2)(3()()1()2)(1)((

)1()2()1(

rn

n

rn

rnrnnnn

rnnnn

We denote this number by P(n,r).Fact: P(n,0)=1, P(n,r)=n!/(n-r)!, P(n,n)=n!.

Fundamental Principles of Counting 17

1.2 Permutations• Example 1.11: The number of arrangements of four letters,

BALL, is 12, not 4!.

2(Number of arrangements of the letters, B, A, L, L) =

(Number of arrangements of the letters, B, A, L1, L2 )

Fundamental Principles of Counting 18

Example 1.12• Example 1.12: The number of arrangements of four

letters, PEPPER(2!)(3!)(Number of arrangements of the letters in PEPPER) =

(Number of permutations of the symbols P1,E1,P2,P3,E2 ,R)

(Number of arrangements of the letters in PEPPER)

=6!/(2!)(3!)=60

Fundamental Principles of Counting 19

1.2 Permutations

• In general, if there are n objects with n1 of a first type, n2 of a second type, …, nr of an rth type, where n1 n2 … nr =n, then there are n!/ n1!n2 ! …nr! Arrangements of the n given objects.

Fundamental Principles of Counting 20

Example 1.13

Fundamental Principles of Counting 21

1.2 Permutations

• Example 1.14:

1

2

3

4

5

1 2 3 4 5 6 7

• How many paths from (2,1) to (7,4)?

– Each path corresponds with a list of five R’s and three U’s.

– 8!/(5!)(3!)=56.

Fundamental Principles of Counting 22

1.2 Permutations

• Example 1.15

Fundamental Principles of Counting 23

1.2 Permutations

• Example 1.16: If six people, designated A, B, …, F, are seated around table, how many different circular arrangement are possible, if arrangements are considered the same when one can be obtained from the other by rotation?

A

B

E

F

C

D

C

D

A

B

E

F

• 6(Number of circular arrangements of A, B, …, F)= (Number of linear arrangements of A, B, …, F)= 6!

6!/6=120

Fundamental Principles of Counting 24

1.2 Permutations

• Example 1.17: Suppose now that the six people of Example 1.16 are three married couples and that A, B, and C are the females. We want to arrange the six people around the table so that the sexes alternate.

Fundamental Principles of Counting 25

1.3 Combinations: The Binomial Theorem(組合,二項式定

理)• Draw three cards from a standard deck, in

succession without replacement, then by the rule of product, there are

possibilities.

)3,52(!49

!52505152 P

Fundamental Principles of Counting 26

1.3 Combinations: The Binomial Theorem

• Each selection, or combination, of three cards, with no reference to order, corresponds to 3! permutations of three cards.

(3!)(Number of selection of size 3 from a deck of 52)

= Number of permutation of size 3 from the 52 cards

= !49

!52)3,52( P

Fundamental Principles of Counting 27

1.3 Combinations: The Binomial Theorem

• In general, if we start with n objects, each selection, or combination, of r of these objects, with no reference to order, corresponds to r! permutations of size r from the n objects.

• Thus the number of combinations of size r from a collection of size n, denoted C(n,r), where 0r n, satisfies (r!)C(n,r)=P(n,r) and

.0,)!(!

!

!

),(),( nr

rnr

n

r

rnPrnC

Fundamental Principles of Counting 28

1.3 Combinations: The Binomial Theorem

• When dealing with any counting problem, we should ask ourselves about the importance of order in the problem.

• When order is relevant, we think in terms of permutations, and arrangements and the rule of product.

• When order is not relevant, combination should play a key role in solving the problem,

Fundamental Principles of Counting 29

Fundamental Principles of Counting 30

1.3 Combinations: The Binomial Theorem

• Example 1.18: Invite 11 of the 20 committee member. Order is not important, so she can invite the “the lucky 11” in C(20,11)=20!/(11!9!) ways.

• Example 1.19: a) Answer any 7 of 10 questions:

b) Answer 3 from the first 5 and 4 from the last 5.

c) Answer 7 of the 10 question, where at least 3 are selected from the first 5.1) Answer 3 of the first 5 and 4 of the last 5.

2) Answer 4 of the first 5 and 3 of the last 5.

3) Answer all 5 of the first 5 and 2 of the last 5.

7

10

505104

5

3

5

1101050502

5

5

5

3

5

4

5

4

5

3

5

Fundamental Principles of Counting 31

1.3 Combinations: The Binomial Theorem

• Example 1.20:a) Select 9 from 28 juniors and 25 seniors.

b) If two juniors and one senior are the best spikers and must be on the team, then the rest of the team can be chosen in

c) For a tournament the team must comprise 4 juniors and 5 seniors. She can select her team in

9

53

6

50

5

25

4

28

Fundamental Principles of Counting 32

1.3 Combinations: The Binomial Theorem

• Example 1.21: Make up four teams, termed A, B, C and D, of nine girls each from the 36 freshman girls.

9

36a) Team A:

Team B:

Team C:

Team D:

9

27

9

18

9

9

!9!9!9!9

!36

!0!9

!9

!9!9

!18

!18!9

!27

!27!9

!36

9

9

9

18

9

27

9

36

a) Distribute 9 A’s, 9 B’s, 9C’s, and 9 D’s in the 36 spaces.

The number of way is the number of arrangements of 36 letters comprising 9 each of A, B, C and D.

!9!9!9!9

!36

Fundamental Principles of Counting 33

Example 1.21

Fundamental Principles of Counting 34

1.3 Combinations: The Binomial Theorem

• Example 1.22: a) The number of arrangements of letters in

TALLAHASSEE is 11!/3!2!2!1!1!.b) How many of these arrangements have no

adjacent A’s?• Disregarding the A’s, there are 8!/2!2!2!1!1!=5040 ways

• Insert 3 A’s in 9 possible locations: (why?)

• Each of the insertion is for all other 5039 arrangements of other letters. By the rule of product, there are 504084=423,360 ways.

3

9

Fundamental Principles of Counting 35

Example 1.21

Fundamental Principles of Counting 36

Summation Notation

Fundamental Principles of Counting 37

Summation

Fundamental Principles of Counting 38

1.3 Combinations: The Binomial Theorem

• Example 1.23:– String made up of prescribed alphabets– E.g. 01, 11, 21, 12, 22, 000, 012,202, 110 of 0,1 and 2– In general, if n is any positive integer, then by the rule of pro

duct there are 3n strings of length n for alphabet 0, 1, and 2.– Define weight of x, wt(x), by wt(X)=x1+x2+x3+…+xn.– e.g. wt(22)=4, wt(12)=3, wt(101)=2, wt(210)=3,...– Among the 310 strings of length 10, we wish to determine ho

w many even weight.– Such a string has even weight precisely when the number of

1’s in the string is even. 1 出現偶數次

Continued

Fundamental Principles of Counting 39

1.3 Combinations: The Binomial Theorem

• Example 1.23:– Six different cases to

consider.1) If the string contains no 1’s,

then each of the 10 positions can be filled with either 0 or 2: 210.

2) Two 1’s: 28.

3) Four 1’s: 26.

4) Six 1’s: 24.

2

10

4

10

6

10

5) Eight 1’s: 22.

6) Ten 1’s: .

– By the rule of sum,

8

10

10

10

10

102

8

102

6

102

4

102

2

102 246810

5

0

21022

10n

n

n

Fundamental Principles of Counting 40

1.3 Combinations: The Binomial Theorem

• Example 1.24:

a) Draw five cards from a standard deck of 52 cards. In how many ways can her selection result in a hand with no clubs?– Ellen is restricted to selecting her five cards from the 39

cards in the deck that are not clubs.

5

39

Continued

Fundamental Principles of Counting 41

1.3 Combinations: The Binomial Theorem

b) We want to count the number of Ellen’s five card selection that contain at least one club.– These are precisely the selections that were not counted in

part (a).– There are possible five-card hands in total, we find

that

5

52

Continued

5

39

5

52

Fundamental Principles of Counting 42

1.3 Combinations: The Binomial Theorem

c) Can we obtain the result in part (b) in another way?– For example, since Ellen wants to have at least one club in

the five-card hand, let her first selection a club.– Now she does not care what comes up for other four cards.

Continued

1

13

4

51

5

39

5

52

4

51

1

13

– Something wrong!

3 5 K 7 J

5 3 K 7 J

K 3 5 7 J

Over-counting

Fundamental Principles of Counting 43

1.3 Combinations: The Binomial Theorem

d) Any other way to arrive at the answer in part (b)?

0

39

5

13

1

39

4

13

2

39

3

13

3

39

2

13

4

39

1

13

5

1 5

3913

i ii

Fundamental Principles of Counting 44

1.3 Combinations: The Binomial Theorem

• Note: C(n,r)=C(n,n-r)• Theorem 1.1: The Binomial Theorem. If x and y are variables and n is a po

sitive integer, then

n

k

knknn

nnnn

yxk

nyx

n

nyx

n

n

yxn

yxn

yxn

yx

0

011

22110

1

210)(

Continued

Fundamental Principles of Counting 45

1.3 Combinations: The Binomial Theorem

– In n=4, the coefficient of x2y2 in the expansion of the product (x+y)(x+y)(x+y)(x+y) is the number of ways in which we can select two x’s from the four x’s, one of which is available in each factor.

– For example, among the possibilities, we can select (1) x from the first two factors and y from the last two factors or (2) x from the first and third factors and y from the second and fourth.

Factor selected for x 1) 1,22) 1,33) 1,44) 2,35) 2,46) 3,4

Factor selected for y 1) 3,42) 2,43) 2,34) 1,45) 1,36) 1,2

Continued

Fundamental Principles of Counting 46

1.3 Combinations: The Binomial Theorem

– Consequently, the coefficient of x2y2 in the expansion of (x+y)4 is =6, the number of ways to select two distinct objects from a collection of four distinct objects.

Continued

2

4

Fundamental Principles of Counting 47

1.3 Combinations: The Binomial Theorem

• Proof: In the expansion of the product

The coefficient of xkyn-k, where 0kn, is the number of different ways in which we can select k x’s from the n available factors. The total number of such selections of size k from a collection of size n is C(n,k)= , and from this the binomial theorem follows.

)())()(( yxyxyxyx

k

n

Fundamental Principles of Counting 48

1.3 Combinations: The Binomial Theorem

• Example 1.25:

a) From the binomial theorem it follows that the x5y2 coefficient of (x+y)7 in the expansion of is

b) To obtain the coefficient of a5b2 in the expansion of (2a-3b)7, replace 2a by x and –3b by y.

217

5

5

7

Fundamental Principles of Counting 49

1.3 Combinations: The Binomial Theorem

• Corollary 1.1: For each integer n>0,

0)1(210

)

2210

)

n

nnnnb

n

nnnna

n

n

Fundamental Principles of Counting 50

1.3 Combinations: The Binomial Theorem

• Theorem 1.2: For positive integers n, t, the coefficient of in the expansion of

is

where each ni is an integer with 0 ni n, for all 1 i t, and .

tnt

nnn xxxx 321321

ntxxxx )( 321

nnnnn t 321

!!!!

!

321 tnnnn

n

Fundamental Principles of Counting 51

1.3 Combinations: The Binomial Theorem

• Example 1.26:

a) (x+y+z)7

– x2y2z3

– xyz5

b) We need to know the coefficient of a2b3c2d5 in the expansion of (a+3b-3c+2d+5)16.

!3!2!2

!7

3,2,2

7

!5!1!1

!7

5,1,1

7

Fundamental Principles of Counting 52

1.4 Combinations with Repetition

• When repetitions are allowed, we have seen that for n distinct objects an arrangement of size r of these objects can be obtained in nr ways, for an integer r0.

• We now turn to the comparable problem for combinations and once again obtain a related problem whose solution follows from out previous enumeration principles.

Fundamental Principles of Counting 53

1.4 Combinations with Repetition組合重複問題

• Example 1.27: Seven high school freshmen, each wants one of the following: a cheeseburger (c), a hot dog (h), a taco (乾酪夾餅) (t), or a fish sandwich (f). How many different purchases are possible (買法有幾種) ?– Here we are concerned with how many of each item are pur

chased, not with the order in which they are purchased, so the problem is one of selections, or combinations, with repetition.

Enumerating all arrangements of 10 symbols consisting of 7 x’s and 3 |’s

7

10

!3!7

!10

Fundamental Principles of Counting 54

1.4 Combinations with Repetition (有重複之組合)

• In general, when we wish to select, with repetition, r of n distinct objects, we find that we are considering all arrangements of r x’s and n-1 |’s and that this number is

Consequently, the number of combination of n objects taken r at a time, with repetition, is C(n+r-1,r).

r

rn

nr

rn 1

)!1(!

)!1(

Fundamental Principles of Counting 55

組合重複

• 任意 N 個相異物件,從中選擇 R 件,可重複選取。則類似於考慮 r 個 X 與 n-1 條短線 | 的全部排列數,

r

rn

nr

rn 1

)!1(!

)!1(

Fundamental Principles of Counting 56

1.4 Combinations with Repetition

• Example 1.28: A donut (甜甜圈) shop offer 20 kinds of donuts. Assuming that there are at least a dozen of each kind when we enter the shop, we can select a dozen in

• C(20+12-1,12) =C(31,12)=141,120,525 ways.

Fundamental Principles of Counting 57

1.4 Combinations with Repetition

• Example 1.29: President wishes to distribute among four vice presidents $1000 in Christmas bonus (獎金) checks, where each check will be written for a multiple of $100.a) One or more presidents get nothing. C(4+10-1,10)=C(13,1

0)

b) Each president should receive at least $100. C(4+6-1,6)=C(9,6)

c) If each vice president must get at least $100 and Mona gets at least $500, then

C(3+2-1,2)+C(3+1-1,1)+C(3+0-1,0)=10=C(4+2-1,1)Mona gets exactly $500

Mona gets exactly $600

Mona gets exactly $600

Fundamental Principles of Counting 58

1.4 Combinations with Repetition

• Example 1.30: In how many ways can we distribute 7 apples and 6 oranges among 4 children so that each children receives at least one apple?

– Given each child an apple, we have C(4+3-1,3)=20 ways to distribute the other 3 apples.

– There are C(4+6-1,6)=84 ways to distribute 6 oranges.

– By the rule of product, 2084=1680 ways

Fundamental Principles of Counting 59

1.4 Combinations with Repetition

• Example 1.31: A message is made up of 12 different symbols and is to be transmitted through a communication channel. In addition to 12 symbols, the transmitter will also send a total of 45 spaces between the symbols, with at least three spaces between each pair of consecutive symbols. In how many ways can the transmitter send such a message?

12! C(11+12-1,12)

arrangement of12 different symbols

45-113=12A selection of size 12 from a collection of size 11

Fundamental Principles of Counting 60

1.4 Combinations with Repetition• Example 1.32:Determine all integer solutions to the

equation where xi0 1i 4.– A selection, with repetition, of size 7 from a collection of siz

e 4, so there are C(4+7-1,7) solutions.– 七元分給四人

• At this point it is crucial that we recognize the equivalence of the following:a) The number of integer solutions of the equation

b) The number of selections, with repetition, of size r from a collection of size n.

c) The number of ways r identical objects can be distributed among n containers.

74321 xxxx

.1,0,21 nixrxxx in

Fundamental Principles of Counting 61

Combinations with Repetition

Fundamental Principles of Counting 62

1.4 Combinations with Repetition

• Example 1.33: In how many ways can one distribute 10 (identical) white marbles among 6 distinct containers?– C(6+10-1,10)=3003

10654321 xxxxxx

Fundamental Principles of Counting 63

1.4 Combinations with Repetition

• Example 1.34:How many solutions are there to the inequality – One approach is to determine the number of such solutions t

o where k is an integer and 0k9.

– Transform the problem by noting the correspondence between the the nonnegative integer solutions of the above equation and the integer solution of

– The number of solutions is the same as

where yi=xi, for 1i 6, and y7=x7-1.

10654321 xxxxxx

kxxxxxx 654321

.70,610,107654321 ixxxxxxxx i

97621 yyyy

C(7+9-1,9)

Fundamental Principles of Counting 64

1.4 Combinations with Repetition

• Example 1.36:

a) Let us determine all the different ways in which we can write the number 4 as a sum of positive integers, where the order of summands is considered relevant.

b) partition of integer

1) 4

2) 3+1

3) 1+3

4) 2+2

5) 2+1+1

6) 1+2+1

7) 1+1+2

8) 1+1+1+1

1) 4

2) 3+1

3) 1+3

4) 2+2

5) 2+1+1

6) 1+2+1

7) 1+1+2

8) 1+1+1+1don’t care order

Fundamental Principles of Counting 65

1.4 Combinations with Repetition

• Example 1.36:

b) We wish to count the number of compositions for the number 7.• Consider the number of possible summands.

One summand: 1

If there are two (positive) summands, we want to count the number of integer solutions for w1+w2=7, where w1,w2 >0.

This is equal to the number integer solutions for x1+x2=5, where x1,x2 0.

5

152

Continued

Fundamental Principles of Counting 66

1.4 Combinations with Repetition

• In general, one finds that for each positive integer m, there are

compositions.

6

0

6

0

6

1

6

2

6

3

6

4

6

5

6

6

6

k k

1

0

121m

k

m

k

m

Fundamental Principles of Counting 67

1.4 Combinations with Repetition

• Example 1.37: How many time is the print statement executed?

for i:=1 to 20 do for j:=1 to i do for k:=1 to j do print(i*j+k)

– For the print statement to be executed, it must satisfy the condition 1kji20.

– In fact, any selection a, b, c(abc) of size 3, with repetition allowed, from the list 1, 2, 3, …, 20 results in one of the correct selection: here k=a, j=b, i=c.

3

1320