Download presentation
Presentation is loading. Please wait.
Published byBernice Oliver Modified over 8 years ago
1
Introduction to Counting ICS 6D Sandy Irani
2
The Product Rule The product rule gives a way to count sequences: – Example: lunch special at a restaurant includes a selection of sandwich, side and drink: Sandwiches = {Burger, Grilled chicken, Grilled, cheese} Sides = {Fries, Fruit} Drinks = {Coke, Diet Coke, OJ, Sprite} – A lunch selection is specified by a triple: ( [Sandwich], [Side], [Drink] ) For example: (Burger, Fries, Coke) – The product rule says that the number of distinct lunch choices is: |Sanwiches| x |Sides| x |Drinks| = 3x2x4 = 24
3
The Product Rule For finite sets A 1, A 2,…, A n : |A 1 x A 2 x…x A n |= |A 1 | ∙ |A 2 | ∙ … ∙ |A n | Can see product rule as a sequence of steps in making a selection: multiply the number of choices at each step The product rule works when the number of choices at each step is independent of the choices made so far. Cartesian Product: Elements of this set have the form (a 1, a 2,.., a n ) where each a j ∈ A j
4
Product Rule Example An elementary school has 5 4 th grade classes. The student council consists of one representative chosen from each class. Let C i be the set of kids in class i, i = 1, 2, 3, 4, 5 The number of different selection for the student council:
5
Product Rule Example Athlete training for a triathlon makes her exercise schedule for the week. For each of the 7 days, she can run, swim or bike. How many different schedules are possible?
6
Counting Strings Set of symbols = Σ How many strings of length n over alphabet Σ ? Product rule says: View as a selection process: how many binary strings of length 4?
7
The Sum Rule For finite sets A 1, A 2,…, A n, If the sets are pairwise disjoint (A i ∩ A j = φ, for i≠j) then |A 1 ∪ A 2 ∪ … ∪ A n |= |A 1 | + |A 2 | + … + |A n |
8
The Sum Rule Lunch Special Selections: Sandwiches = {Burger, Grilled chicken, Grilled, cheese} Sides = {Fries, Fruit} Hot Drinks = {Coffee, Tea, Cocoa} Cold Drinks = {Water, Soda} A lunch selection includes a sandwich, a side and a drink. Hot Drinks ∩ Cold Drinks = φ |Drinks| = |Hot Drinks ∪ Cold Drinks| = |Hot Drinks| + |Cold Drinks| (by Sum Rule) # Selections = |Sandwiches|x|Sides|x|Drinks| Sum rule applies because we are picking a hot drink OR a cold drink but not both.
9
Counting Passwords Digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Letters = {A, B, C, D, …., X, Y, Z} How many valid passwords are there if a password must… – be a string of letters or digits of length 7? – be a string of letters or digits of length 7 and start with a letter?
10
Counting Passwords Digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Letters = {A, B, C, D, …., X, Y, Z} How many valid passwords are there is a password must be a string of letters or digits of length 6, 7, or 8?
11
Bijection Rule Let S and T be two finite sets. If there is a bijection from S to T, then |S| = |T| Bijection between a lunch special selection and triples of the form: ( [Sandwich], [Side], [Drink] )
12
Bijection rule X = {x 1, x 2,…, x n } What is |P(X)|? f: P(X) → {0,1} n – If f is a bijection, then |P(X)| = |{0, 1} n | = 2 n A ⊆ X, f(A) = y – x i ∈ A ↔ i th bit of y is 1. Example: n = 7, X = {a, b, c, d, e, f, g}
13
Bijection Rule Example A string is a palindrome if it is the same after it is reversed. Let P 6 be the set of all 6-bit strings that are also palindromes. Bijection between {0, 1} 3 and P 6 f: {0, 1} 3 → P 6 f(x) = xx R (x R is the reverse of x)
14
K-to-1 Rule Each kid at a slumber party leaves her shoes at the door. To count the number of kids at the party, count the number of shoes and divide by 2.
15
K-to-1 Rule Let X and Y be finite sets. A k-to-1 correspondence is a function f: X→Y such that for each y ∈ Y, there are exactly k different x ∈ X such that f(x) = y. If there is a k-to-1 correspondence from X to Y then |Y| = |X|/k
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.