Download presentation
Presentation is loading. Please wait.
Published bySophia Cunningham Modified over 9 years ago
1
The Basics of Counting: Selected Exercises
2
Copyright © Peter Cappello2 Sum Rule Example There are 3 sizes of pink shirts & 7 sizes of blue shirts. How many types of shirts are there, if a shirt type is a shirt of a particular color in a particular size? PinkBlue
3
Copyright © Peter Cappello3 Sum Rule A B = |A B| = |A| + |B|. AB
4
Copyright © Peter Cappello4 Sum Rule Generalization Let { S 1, S 2, …, S n } be a partition of S. Then, | S | = | S 1 | + | S 2 | + … + | S n |. When using the sum rule, 1.Check 1: Have I partitioned S? 1.Are the subsets pairwise disjoint? 2.Is their union equal to S? 2.Check 2: What equivalence relation corresponds to my partition?
5
Copyright © Peter Cappello5 Product Rule Let A be a set of elements constructed in 2 stages. Stage 1 has n 1 possible outcomes. Stage 2 has n 2 possible outcomes. Then, | A | = n 1 n 2.
6
Copyright © Peter Cappello6 Product Rule Example A store sells pink shirts & blue shirts; each comes in small, medium, & large. How many types of shirts are there? A shirt type can be described as an ordered pair: (color, size).
7
Copyright © Peter Cappello7 Product Rule: Counting Ordered Pairs Let A be a set of objects that are constructed (described) in 2 stages. Let S be the set of values from stage 1 Let T be the set of values from stage 2 Then, | A | = | S | x | T |. An element of A can be described as an ordered pair (a, b), where a S & b T.
8
Copyright © Peter Cappello8 Product Rule Example How many sequences of 2 distinct letters are there from { a, e, i, o, u } ? 1.There are 5 ways to select the 1 st letter in the sequence. 2.There are 4 ways to select the 2 nd letter in the sequence. The set of values in stage 2 depends on which letter was selected in stage 1. The size of the set of values in stage 2 does not depend on which letter was chosen in stage 1.
9
Copyright © Peter Cappello9 9 Product Rule: Counting Ordered Pairs The product rule is a special case of the sum rule: When 1.{ S 1, S 2, …, S n } is a partition of A 2.| S i | = | S j |, for 1 ≤ i, j ≤ n The sum rule reduces to the product rule: | S 1 | + | S 2 | + … + | S n | = n| S 1 |.
10
Copyright © Peter Cappello10 Exercise 10 How many bit strings are there of length 8?
11
Copyright © Peter Cappello11 Exercise 10 How many bit strings are there of length 8? Use the product rule: Count the bit strings of length 8 by decomposing the process into 8 stages: count the possibilities for: the 1 st bit (2), the 2 nd bit (2), …, the 8 th bit (2). The product: 2 8 = 256 different bit strings.
12
Copyright © Peter Cappello12 Exercise 20 How many positive integers < 1000 1.Are divisible by 7?
13
Copyright © Peter Cappello13 Exercise 20 How many positive integers < 1000 1.Are divisible by 7? └ 999/7 ┘ = 142. 2.Are divisible by 7 & 11? (Use a Venn diagram)
14
Copyright © Peter Cappello14 Exercise 20 How many positive integers < 1000 1.Are divisible by 7? └ 999/7 ┘ = 142. 2.Are divisible by 7 & 11? └ 999/(7. 11) ┘ = 12. 3.Are divisible by 7 but not by 11? (Use a Venn diagram)
15
Copyright © Peter Cappello15 Exercise 20 How many positive integers < 1000 1.Are divisible by 7? └ 999/7 ┘ = 142. 2.Are divisible by 7 & 11? └ 999/(7. 11) ┘ = 12. 3.Are divisible by 7 but not by 11? 1.Count the # divisible by 7; 2.Subtract the # divisible by 7 & 11; └ 999/7 ┘ - └ 999/(7. 11) ┘ = 142 – 12 = 130.
16
Copyright © Peter Cappello16 Exercise 20 continued 4. Are divisible by 7 or 11? (Use a Venn diagram)
17
Copyright © Peter Cappello17 Exercise 20 continued 4. Are divisible by 7 or 11? We want property A or property B: use inclusion-exclusion: 1.Count the # that are divisible by 7; 2.Add the # that are divisible by 11; 3.Subtract the # that are divisible by both; └ 999/7 ┘ + └ 999/11 ┘ – └ 999/(77) ┘ = 142 + 90 – 12. 711
18
Copyright © Peter Cappello18 Exercise 20 continued 5. Are divisible by exactly one of 7 & 11?
19
Copyright © Peter Cappello19 Exercise 20 continued 5. Are divisible by exactly one of 7 & 11? What region of the Venn diagram represents the answer? Count the symmetric difference: (union – intersection) 1.Count the # that are divisible by 7 or 11; └ 999/7 ┘ + └ 999/11 ┘ – └ 999/(7. 11) ┘ = 142 + 90 – 12 =220. 2.Subtract the # that are divisible by both; └ 999/(7. 11) ┘ = 12. 711
20
Copyright © Peter Cappello20 Exercise 20 continued 6. Are divisible by neither 7 nor 11? What region of the Venn diagram represents the answer?
21
Copyright © Peter Cappello21 Exercise 20 continued 6. Are divisible by neither 7 nor 11? What region of the Venn diagram represents the answer? 1.Count the universe (999). 2.Subtract the # that is divisible by 7 or 11 (220) giving 779. 711
22
Copyright © Peter Cappello22 Exercise 20 continue 7. Have distinct digits?
23
Copyright © Peter Cappello23 Exercise 20 continue 7. Have distinct digits? Use the sum rule to decompose the problem into counting 1.The # of 1-digit numbers: 9 2.The #vof 2-digit numbers with distinct digits: Use the product rule: 1.Count the # of ways to select the 10s digit: 9 2.Count the # of ways to select the unit digit: 9 3.There are 9. 9 = 81 distinct 2-digit numbers. 3.The # of 3-digit numbers with distinct digits: Use the product rule: 1.Count the # of ways to select the 100s digit: 9 2.Count the # of ways to select the 10s digit: 9 3.Count the # of ways to select the unit digit: 8 4.There are 9. 9. 8 = 648 distinct 3-digit numbers. The overall answer is 9 + 81 + 648 = 738.
24
Alternate approach –Make a 3-level tree of 3-digit numbers Top level (100s digit): branch: 0 vs. !0 Middle level (10s digit): branch: 0 vs. !0 Bottom level (1s digit): branch: 0 vs. !0 –Add the solutions for the branches representing 3-digit numbers with distinct digits. Copyright © Peter Cappello24
25
1.000: Invalid 2.00X: 9 3.0X0: 9 4.0XY: 9 x 8 = 72 5.X00: Invalid 6.X0Y: 9 x 8 = 72 7.XY0: 9 x 8 = 72 8.XYZ: 9 x 8 x 7 = 504 Sum = 738 Copyright © Peter Cappello25
26
Sara’s approach Count complement set; subtract from 999. Sum rule: Exactly 2 digits the same: –2-digit numbers: 9 –3-digit numbers: »No “0”: XYY | YXY | YYX: 9 x 8 x 3 »1 “0”: X0X | XX0: 9 x 2 »2 “0”: X00: 9 Exactly 3 digits the same: XXX: 9 Sum: 9 + 216 + 18 + 9 + 9 = 261; 999 – 261 = 738 Copyright © Peter Cappello26
27
Copyright © Peter Cappello27 Exercise 30 How many strings of 8 English letters are there: a)If letters can be repeated?
28
Copyright © Peter Cappello28 Exercise 30 How many strings of 8 English letters are there: a)If letters can be repeated? Use product rule: (26) 8 b)If no letter can be repeated?
29
Copyright © Peter Cappello29 Exercise 30 How many strings of 8 English letters are there: a)If letters can be repeated? Use product rule: (26) 8 b)If no letter can be repeated? Use product rule: 26. 25. 24. 23. 22. 21. 20. 19 c) That start with X, if letters can be repeated?
30
Copyright © Peter Cappello30 Exercise 30 How many strings of 8 English letters are there: a)If letters can be repeated? Use product rule: (26) 8 b)If no letter can be repeated? Use product rule: 26. 25. 24. 23. 22. 21. 20. 19 c) That start with X, if letters can be repeated? Use product rule: 1. (26) 7 d) That start with X, if no letter can be repeated?
31
Copyright © Peter Cappello31 Exercise 30 How many strings of 8 English letters are there: a)If letters can be repeated? Use product rule: (26) 8 b)If no letter can be repeated? Use product rule: 26. 25. 24. 23. 22. 21. 20. 19 c) That start with X, if letters can be repeated? Use product rule: 1. (26) 7 d) That start with X, if no letter can be repeated? Use product rule: 1. 25. 24. 23. 22. 21. 20. 19 e) That start & end with X, if letters can be repeated?
32
Copyright © Peter Cappello32 Exercise 30 How many strings of 8 English letters are there: a)If letters can be repeated? Use product rule: (26) 8 b)If no letter can be repeated? Use product rule: 26. 25. 24. 23. 22. 21. 20. 19 c) That start with X, if letters can be repeated? Use product rule: 1. (26) 7 d) That start with X, if no letter can be repeated? Use product rule: 1. 25. 24. 23. 22. 21. 20. 19 e) That start & end with X, if letters can be repeated? Use product rule: 1. 1. (26) 6
33
Copyright © Peter Cappello33 Exercise 30 continued f) That start with the letters BO, if letters can be repeated?
34
Copyright © Peter Cappello34 Exercise 30 continued f) That start with the letters BO, if letters can be repeated? Use product rule: 1. 1. (26) 6 g) That start & end with the letters BO, if letters can be repeated?
35
Copyright © Peter Cappello35 Exercise 30 continued f) That start with the letters BO, if letters can be repeated? Use product rule: 1. 1. (26) 6 g) That start & end with the letters BO, if letters can be repeated? Use product rule: 1. 1. 1. 1. (26) 4 h) That start or end with the letters BO, if letters can be repeated?
36
Copyright © Peter Cappello 201136 h) That start or end with letters BO, if letters can be repeated? Use inclusion-exclusion: a)That start with the letters BO, if letters can be repeated: (26) 6 b)That end with the letters BO, if letters can be repeated: (26) 6 c)Subtract those that start and end with the letters BO, if letters can be repeated: (26) 4 Overall answer: 2. (26) 6 - (26) 4 Exercise 30 continued End w/ BO Start w/ BO
37
Copyright © Peter Cappello37 Exercise 40 How many ways can a wedding photographer arrange 6 people in a row from a group of 10, where the bride & groom are among these 10, if a)The bride is in the picture?
38
Copyright © Peter Cappello38 Exercise 40 How many ways can a wedding photographer arrange 6 people in a row from a group of 10, where the bride & groom are among these 10, if a)The bride is in the picture? Use the product rule: a)Pick the position of the bride: 6 b)Place the remaining 5 people from left to right in the remaining positions (use the product rule to do this): 9. 8. 7. 6. 5 Overall answer is 6. 9. 8. 7. 6. 5.
39
Copyright © Peter Cappello39 Exercise 40 continued b) Both the bride & groom are in the picture?
40
Copyright © Peter Cappello40 Exercise 40 continued b) Both the bride & groom are in the picture? Use the product rule: a)Pick the bride’s position: 6 b)Pick the groom’s position: 5 c)Place 4 people from the remaining 8 in the remaining 4 slots, from left to right: 8. 7. 6. 5. The overall answer is 6. 5. 8. 7. 6. 5.
41
Copyright © Peter Cappello41 Exercise 40 continued c) Exactly 1 of the bride & groom is in the picture?
42
Copyright © Peter Cappello42 40 continued c) Exactly 1 of the bride & groom is in the picture? (symmetric difference of what?) 1.Pick either the bride or the groom: 2. 2.Place that person in the picture: 6. 3.Place remaining 5 from remaining 8 people: P(8, 5) = 8. 7. 6. 5. 4. The overall answer is 2. 6. 960 = 80,640.
43
Copyright © Peter Cappello43 Exercise 50 –A variable name in C can have uppercase & lowercase letters, digits, or underscores. –The name’s 1 st character is a letter (uppercase or lowercase), or an underscore. –The name of a variable is determined by its 1 st 8 characters. How many different variables can be named in C?
44
Copyright © Peter Cappello44 Exercise 50 A variable name in C can have uppercase & lowercase letters, digits, or underscores. The name’s 1 st character is a letter (uppercase or lowercase), or an underscore. The name of a variable is determined by its 1 st 8 characters. How many different variables can be named in C? Use the sum rule to count the # of variable names of i characters, for i = 1, 2, …, 8. The overall answer is the sum of these numbers.
45
Copyright © Peter Cappello45 Exercise 50 continued Use the product rule to count the # of names of a fixed size. Let the name have i characters. 1.The # of ways to pick the 1 st character is 2. 26 + 1 = 53. 2.The # of ways to pick subsequent characters is 53 + 10. The # of ways to pick the name is 53. (63) i-1. The overall answer is Σ i=[1,8] 53. (63) i-1 ≈ 2.1 x 10 14.
46
Copyright © Peter Cappello46 End
47
Copyright © Peter Cappello47 Product Rule: Counting Ordered Pairs Let A be a set of objects constructed (described) in 2 stages. Let S be the set of values from stage 1. If a S is selected in stage 1, let T a be the set of values for stage 2. Essentially, A = { ( a, b ) | a S and b T a }. To use the product rule, for all a, b S, | T a | = | T b |. (Illustrate S and T a with previous examples) The product rule is a special case of the sum rule: When 1.{ S 1, S 2, …, S n } is a partition of A 2.| S i | = | S j |, for 1 ≤ i, j ≤ n The sum rule reduces to the product rule: | S 1 | + | S 2 | + … + | S n | = n| S 1 |.
48
Copyright © Peter Cappello48 Characters . ≥ ≡ ~ ┌ ┐ └ ┘ ≈ Ω Θ Σ
49
Copyright © Peter Cappello49 Exercise 20 continue 8. Have distinct digits and are even?
50
Copyright © Peter Cappello50 Exercise 20 continue 8. Have distinct digits and are even? Easier to: 1.count the number that have distinct digits (738) 2. subtract those that are odd: 1.1-digit: 5 2.2-digit: 40 1.5 ways to pick the unit digit 2.8 ways to pick the 10s digit (nonzero) 3.3-digit: 320 1.5 ways to pick the unit digit 2.8 ways to pick the 100s digit (nonzero) 3.8 ways to pick the 10s digit The total that have distinct digits & are odd is 5 + 40 + 320 = 365. The overall answer is 738 – 365 = 373.
51
Copyright © Peter Cappello51 20 continued The hard way: Use the sum rule directly: 1.1-digit: 4 2.2-digit: 0 is not picked: 40 is picked: 1low-order digit: high-order digit: 9 8 9 + 32 = 41
52
Copyright © Peter Cappello52 20 continued 3. 3-digit: 0 is not picked: 40 is picked: 1low-order digit: high-order digit: 9 8 72 + 256 = 328 88 middle digit: The overall answer is 4 + 41 + 328 = 373.
53
Copyright © Peter Cappello53 40 continued c) Exactly 1 of the bride & groom is in the picture? 1.There are 6. 9. 8. 7. 6. 5 ways for the bride to be in the picture. 2.There are 6. 5. 8. 7. 6. 5. ways for the bride and groom to be in the picture. 3.The number of ways for the bride only to be in the picture is 6. 9. 8. 7. 6. 5 - 6. 5. 8. 7. 6. 5 = 6. 8. 7. 6. 5 (9 – 5) = 40,320. 4.There are the same number of ways for the groom only to be in the picture (a 1-to-1 correspondence between bride-only & groom-only) The overall answer is 2. 40,320.
54
Copyright © Peter Cappello54 40 alternate answer for part c c) Exactly 1 of the bride & groom is in the picture? Use the product rule: 1.Pick the bride or groom to be in the picture: 2. 2.Count the number of ways to fill out that picture. Use the product rule: 1.Place the bride/groom: 6 2.Fill in the other positions from left to right: 8. 7. 6. 5. 4. The overall answer is 2. 6. 8. 7. 6. 5. 4 = 80,640.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.