Presentation is loading. Please wait.

Presentation is loading. Please wait.

Counting I: Bijection and Choice Trees

Similar presentations


Presentation on theme: "Counting I: Bijection and Choice Trees"— Presentation transcript:

1 Counting I: Bijection and Choice Trees
Great Theoretical Ideas In Computer Science Victor Adamchik CS Spring 2006 Lecture 5 Jan 31, 2006 Carnegie Mellon University Counting I: Bijection and Choice Trees

2 Not everything that can be counted counts, and not everything that counts can be counted.
A. Einstein

3 If I have 14 teeth on the top and 12 teeth on the bottom, how many teeth do I have in all?

4 How many seats in this auditorium?
Hint: Count without counting!

5 Addition Rule Let A and B be two disjoint finite sets.
The size of AB is the sum of the size of A and the size of B.

6 Corollary (by induction)
Let A1, A2, A3, …, An be disjoint, finite sets.

7 Suppose I roll a white die and a black die.

8 S  Set of all outcomes where the dice show different values. S = ?
T  set of outcomes where the two dice agree. Two ways of counting… |S| =

9 S  Set of all outcomes where the dice show different values. S = ?
T  set of outcomes where the two dice agree.

10 S  Set of all outcomes where the black die shows a smaller number than the white die. S = ?
Ai  set of outcomes where the black die says i and the white die says something larger.

11 S  Set of all outcomes where the black die shows a smaller number than the white die. S = ?
L  set of all outcomes where the black die shows a larger number than the white die. S + L = 30 It is clear by symmetry that S = L. Therefore S = 15

12 It is clear by symmetry that S = L.

13 Pinning down the idea of symmetry by exhibiting a correspondence.
Let’s put each outcome in S in correspondence with an outcome in L by swapping the color of the dice. S L

14 Pinning down the idea of symmetry by exhibiting a correspondence.
Let’s put each outcome in S in correspondence with an outcome in L by swapping the color of the dice. Each outcome in S gets matched with exactly one outcome in L, with none left over. Thus: S = L.

15 Let f:A®B be a function from a set A to a set B.
What is a function??? Read ’s textbook, ch. 6

16 Let f:A®B be a function from a set A to a set B.
f is 1-1 (or injective) if and only if x,yÎA, x ¹ y Þ f(x) ¹ f(y) f is onto (or surjective) if and only if zÎB xÎA f(x) = z There Exists For Every

17  1-1 f:A®B Þ A £ B A B

18  onto f:A®B Þ A  B A B

19  bijection f:A®B Þ A = B

20 1-1 Onto Correspondence (just “correspondence” for short)
A B

21 Correspondence Principle
If two finite sets can be placed into 1-1 onto correspondence, then they have the same size.

22 Correspondence Principle
If two finite sets can be placed into 1-1 onto correspondence, then they have the same size. It’s one of the most important mathematical ideas of all time!

23 Question: How many n-bit sequences are there?
 0  1  2  3 ... 1…  2n-1 2n sequences

24 S = a,b,c,d,e has many subsets.
a, a,b, a,d,e, a,b,c,d,e, e, Ø, … The empty set is a set with all the rights and privileges pertaining thereto.

25 1 means “TAKE IT” 0 means “LEAVE IT”
Question: How many subsets can be formed from the elements of a 5-element set? a b c d e 1 b c e 1 means “TAKE IT” 0 means “LEAVE IT”

26 Question: How many subsets can be formed from the elements of a 5-element set?
1 Each subset corresponds to a 5-bit sequence (using the “take it or leave it” code)

27 a1 a2 a3 … an b1 b2 b3 bn f(b) = ai | bi=1 
S = a1, a2, a3,…, an b = b1b2b3…bn a1 a2 a3 an b1 b2 b3 bn f(b) = ai | bi=1 

28 a1 a2 a3 … an b1 b2 b3 bn f(b) = ai | bi=1 
f is 1-1: Any two distinct binary sequences b and b’ have a position i at which they differ. Hence, f(b) is not equal to f(b’) because they disagree on element ai.

29 a1 a2 a3 … an b1 b2 b3 bn f(b) = ai | bi=1 
f is onto: Let S be a subset of {a1,…,an}. Let bk = 1 if ak in S; bk = 0 otherwise. f(b1b2…bn) = S.

30 The number of subsets of an n-element set is 2n.

31 I own 3 beanies and 2 ties. How many different ways can I dress up in a beanie and a tie?

32

33 Choice Tree A choice tree is a rooted, directed tree with an object called a “choice” associated with each edge and a label on each leaf.

34 A choice tree provides a “choice tree representation” of a set S, if
Each leaf label is in S No two leaf labels are the same

35 Choice Tree for 2n n-bit sequences
1 We can use a “choice tree” to represent the construction of objects of the desired type.

36 2n n-bit sequences 1 000 001 010 011 100 101 110 111 Label each leaf with the object constructed by the choices along the path to the leaf.

37 1 2 choices for first bit X 2 choices for second bit X 2 choices for third bit … X 2 choices for the nth

38 We will now combine the correspondence principle with the leaf counting lemma to make a powerful counting rule for choice tree representation.

39 Product Rule IF S has a choice tree representation with P1 possibilities for the first choice, P2 for the second, and so on, THEN there are P1P2P3…Pn objects in S

40 Product Rule Suppose that all objects of a type S can be constructed by a sequence of choices with P1 possibilities for the first choice, P2 for the second, and so on. IF 1) Each sequence of choices constructs an object of type S AND 2) No two different sequences create the same object THEN there are P1P2P3…Pn objects of type S.

41 How many different orderings of deck with 52 cards?
What type of object are we making? Ordering of a deck Construct an ordering of a deck by a sequence of 52 choices: 52 possible choices for the first card; 51 possible choices for the second card; 50 possible choices for the third card; 1 possible choice for the 52cond card.

42 How many different orderings of deck with 52 cards?
By the product rule: 52 * 51 * 50 * … * 3 * 2 * 1 = 52! 52 “factorial” orderings

43 The number of permutations of n distinct objects is n!
A permutation or arrangement of n objects is an ordering of the objects. The number of permutations of n distinct objects is n!

44 How many sequences of 7 letters are there?
267

45 How many sequences of 7 letters contain at least two of the same letter?
*25*24*23*22*21*20

46 Sometimes it is easiest to count the number of objects with property Q, by counting the number of objects that do not have property Q.

47 Ordered Versus Unordered
From a set of {1,2,3} how many ordered pairs can be formed? How many unordered pairs?

48 Ordered Versus Unordered
From a deck of 52 cards how many ordered pairs can be formed? 52 * 51 How many unordered 5 card hands? pairs? 52*51 / 2  divide by overcount

49 A combination or choice of r out of n objects is an (unordered) set of r of the n objects.
The number of r combinations of n objects: n choose r

50 The number of subsets of size r that can be formed from an n-element set is:

51 How many 8 bit sequences have two 0’s and six 1’s?
1) Choose the set of 2 positions to put the 0’s. The 1’s are forced. 2) Choose the set of 6 positions to put the 1’s. The 0’s are forced.

52 How many 8 bit sequences have two 0’s and six 1’s?
Tempting, but incorrect: 8 ways to place first 0 times 7 ways to place second 0 Violates condition 2 of product rule! Choosing position i for the first 0 and then position j for the second 0 gives the same sequence as choosing position j for the first 0 and position i for the second.

53 How many hands have at least 3 aces?

54 How many hands have at least 3 aces?
How many hands have exactly 3 aces? How many hands have exactly 4 aces? = 4560

55 At least one of the two counting arguments is not correct.
4704  4560 At least one of the two counting arguments is not correct.

56 Four different sequences of choices produce the same hand
A A A A K A A A  A K A A A A K A A A A K

57 1) Choose 3 of 4 aces 2) Choose 2 non-ace cards
A Q A A K The aces came from the first choice and the non-aces came from the second choice.

58 1) Choose 4 of 4 aces 2) Choose 1 non-ace
A A A A K The aces came from the first choice and the non-ace came from the second choice.

59 Study Bee Correspondence Principle Choice Tree Product Rule
If two finite sets can be placed into 1-1 onto correspondence, then they have the same size Choice Tree Product Rule two conditions Counting by complementing it’s sometimes easier to count the “opposite” of something Binomial coefficient Number of r sets of an n set Study Bee


Download ppt "Counting I: Bijection and Choice Trees"

Similar presentations


Ads by Google