312 likes | 506 Views
Discrete and Combinatorial Mathematics R. P. Grimaldi , 5 th edition, 2004. Chapter 1 Fundamental Principles of Counting. Issues of Counting. How many license plates like AB-1234 are there?.
E N D
Discrete and Combinatorial MathematicsR. P. Grimaldi,5th edition, 2004 Chapter 1 Fundamental Principles of Counting
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.
The Rule of Sum “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 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.
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. #
More Examples How 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: 10115 Numbers that end with “5”: 1011 Total: 10115 + 1011 = 600,000,000,000. #
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. #
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). #
Examples 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. #
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.)
Answer 1 How 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.
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: .
Answer 2 How 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: .
Example How many routes are there from the lower-left corner to the upper-right corner of an mn grid in which we restricted to traveling only to the right or upward? Answer: . #
Combinations How many ways can you select r objects out of n?(without concern for the order of selection) Answer: Say: “n choose r”. Despite the fraction, C(n,r) will always be an integer.
Because: we have Also: Combinations
Summations The 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
Binomial Theorem If x an y are variables and n is a positive integer, then 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). #
Pascal’s 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 …
More Combinations Q: 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?
Multinomial Theorem For 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. 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 #
Combinations with Repetitions 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 Consider 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.
Summary When 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? Repetition allowed? Orderingrelevant?
Brainstorm 騎士在旅途中遇見三位美女,其中有天使也有魔鬼。天使向來只說真話,而魔鬼總是說謊。三位美女A,B,C的對話如下: A: B和C之中,至少有一位是天使。 B: A和C之中,至少有一位是魔鬼。 C: 我來告訴你正確的道路。 問題:有幾位天使?