1 Counting by Mapping Lecture 15: Nov 4 A B …… f.

Slides:



Advertisements
Similar presentations
Counting. Counting in Algorithms How many comparisons are needed to sort n numbers? How many steps to compute the GCD of two numbers ? How many steps.
Advertisements

5.3 Permutations and Combinations
7.5 Inclusion/Exclusion. Definition and Example- 2 sets |A  B| =|A| + |B| - |A ∩ B| Ex1: |A|=9, |B|=11, |A∩B|=5, |A  B| = ?
1 More Counting by Mapping Lecture 16: Nov 7. 2 This Lecture Division rule Catalan number.
Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
Mathematical Induction II Lecture 14: Nov
Sets Lecture 11: Oct 24 AB C. This Lecture We will first introduce some basic set theory before we do counting. Basic Definitions Operations on Sets Set.
Great Theoretical Ideas in Computer Science.
Functions, Pigeonhole Principle Lecture 14: Nov 4 A B f( ) =
Multiplication Rule. A tree structure is a useful tool for keeping systematic track of all possibilities in situations in which events happen in order.
Discrete Structures & Algorithms Counting Counting I: One-To-One Correspondence and Choice Trees.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Functions f( ) = A B Lecture 15: Nov 4.
Polynomial time approximation scheme Lecture 17: Mar 13.
More Counting Lecture 16: Nov 9 A B …… f. Counting Rule: Bijection If f is a bijection from A to B, then |A| = |B| A B …… f.
Discrete Mathematics Lecture 6 Alexander Bukharovich New York University.
The Basics of Counting: Selected Exercises. Copyright © Peter Cappello2 Sum Rule Example There are 3 sizes of pink shirts & 7 sizes of blue shirts. How.
Chapter 8 The principle of Inclusion and Exclusion Yen-Liang Chen Dept of Information Management National Central University.
Functions A B f( ) =. This Lecture We will define a function formally, and then in the next lecture we will use this concept in counting. We will also.
How many ways are there to pass through city A where the arrows represent one-way streets? Answer: mn ways The counting principal: Suppose two experiments.
More Counting Lecture 13 A B …… f. Counting Rule: Bijection If f is a bijection from A to B, then |A| = |B| A B …… f.
More Counting Lecture 16: Nov 9 A B …… f. This Lecture We will study how to define mappings to count. There will be many examples shown. Bijection rule.
Chapter 6 The Inclusion-Exclusion Principle and Applications
Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 6 Counting and Probability Instructor: Hayk Melikyan Today we will review sections 6.4,
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Generalized Permutations and Combinations
Binomial Coefficients, Inclusion-exclusion principle
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
March 10, 2015Applied Discrete Mathematics Week 6: Counting 1 Permutations and Combinations How many different sets of 3 people can we pick from a group.
1 CSC 321: Data Structures Fall 2013 Counting and problem solving  mappings, bijection rule  sequences, product rule, sum rule  generalized product.
Great Theoretical Ideas in Computer Science.
Minimisation ENEL111. Minimisation Last Lecture  Sum of products  Boolean algebra This Lecture  Karnaugh maps  Some more examples of algebra and truth.
Generating Functions and Counting Trees. Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve.
COMPSCI 102 Discrete Mathematics for Computer Science.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
1 CS 140 Discrete Mathematics Combinatorics And Review Notes.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science V. AdamchikCS Spring 2006 Lecture 6Feb 2, 2005Carnegie.
CS Lecture 8 Developing Your Counting Muscles.
Section 1.3 Each arrangement (ordering) of n distinguishable objects is called a permutation, and the number of permutations of n distinguishable objects.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Section 6.4. Powers of Binomial Expressions Definition: A binomial expression is the sum of two terms, such as x + y. (More generally, these terms can.
Section Basic Counting Principles: The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n 1.
L14: Permutations, Combinations and Some Review EECS 203: Discrete Mathematics.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
Section 6.3. Section Summary Permutations Combinations.
Fifteen Puzzle Move: can move a square adjacent to the empty square to the empty square.
The Pigeonhole Principle
Developing Your Counting Muscles
CSC 321: Data Structures Fall 2015 Counting and problem solving
Section 16 Inclusion/Exclusion
COCS DISCRETE STRUCTURES
Generalized Permutations & Combinations: Selected Exercises
Mathematical Induction II
Gray Code Can you find an ordering of all the n-bit strings in such a way that two consecutive n-bit strings differed by only one bit? This is called the.
CS100: Discrete structures
COUNTING AND PROBABILITY
Counting I: Bijection and Choice Trees
Basic Counting.
COUNTING AND PROBABILITY
More Counting A B … f Lecture 16: Nov 9.
Basic Counting Lecture 9: Nov 5, 6.
Counting II: Recurring Problems And Correspondences
6.4b The Piano Method (aka: Sticks and Stones Method)
Counting II: Recurring Problems And Correspondences
Counting I: Choice Trees and Correspondences
Presentation transcript:

1 Counting by Mapping Lecture 15: Nov 4 A B …… f

2 Plan We will study how to define mappings to count. There will be many examples shown. Bijection rule (this set of slides) Division rule (next set of slides) More mapping (next set of slides)

3 Counting Rule: Bijection If f is a bijection from A to B, then |A| = |B| A B …… f To compute |A|, one strategy is to define a bijection of A and B, where B is easier to count and we can compute |B| directly.

4 How many subsets of a set S? P(S) = the power set of S = the set of all subsets of S for S = {a, b, c}, P(S) = { , {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c} } Power Set Suppose S has n elements. How large is the power set of S?

5 Bijection: Power Set and Binary Strings S: {s 1, s 2, s 3, s 4, s 5, …, s n } We define a bijection f between subsets and binary strings A B …… f A: the set of all subsets of S B: the set of all n-bit strings The mapping f :A->B is defined in the following way: Given a subset T, we define f(T) as an n-bit string with the i-th bit equal to 1 if and only if s i is in T.

6 Bijection: Power Set and Binary Strings S: {a,b,c} , {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c} P(S)P(S)3-bit strings

7 Bijection: Power Set and Binary Strings This mapping is a bijection, because  two different subsets are mapped to two different strings (injection)  each binary string is mapped by some subset (surjection). So, |P(S)| = |n-bit binary strings| = 2 n. string: … 1 subset: {s 1, s 3, s 4, …, s n } The mapping is defined in the following way: A B …… f Therefore, |A| = |B|, and |B| can be computed directly.

8 There is a bijection between Full Houses and sequences specifying: 1. The value of the triple, which can be chosen in 13 ways. 2. The suits of the triple, which can be selected in (4 3) ways. 3. The value of the pair, which can be chosen in 12 ways. 4. The suits of the pair, which can be selected in (4 2) ways. Bijection: Full House We have used this idea before when we counted poker hands. A B …… f A: the set of full houses B: the set of sequences which satisfy (1)-(4).

9 A Chess Problem In how many different ways can we place a pawn (p), a knight (k), and a bishop (b) on a chessboard so that no two pieces share a row or a column?

10 We define a mapping f between configurations to sequences (r(p), c(p), r(k), c(k), r(b), c(b)), where r(p), r(k), and r(b) are distinct rows, and c(p), c(k), and c(b) are distinct columns. A Chess Problem A B …… f A: the set of the configurations of the 3 pieces B: the set of the such sequences of 6 numbers If we can define a bijection between A and B, and also calculate |B|, then we can determine |A|.

11 We define a mapping f between configurations to sequences (r(p), c(p), r(k), c(k), r(b), c(b)), where r(p), r(k), and r(b) are distinct rows, and c(p), c(k), and c(b) are distinct columns. A Chess Problem (7,6,2,5,5,2) (7,6) (2,5) (5,2) This is a bijection, because:  no two configs map to same sequence (injection)  every such sequence is mapped (surjection) So, to count the number of chess configurations, it is equivalent to count the number of such sequences. f

12 A Chess Problem We define a mapping between configurations to sequences (r(p), c(p), r(k), c(k), r(b), c(b)), where r(p), r(k), and r(b) are distinct rows, and c(p), c(k), and c(b) are distinct columns. Using the generalized product rule, there are 8 choices of r(p) and c(p), there are 7 choices of r(k) and c(k), there are 6 choices of r(b) and c(b). (7,6,2,5,5,2) Thus, total number of configurations = (8x7x6) 2 =

13 Counting Rule: Bijection If f is a bijection from A to B, then |A| = |B| A B …… f Steps: 1)Come up with B. 2)Come up with f. 3)Show f is a bijection. 4)Compute |B|. Usually the first two steps are more difficult. Now we see some more interesting examples.

14 Counting Doughnut Selections There are five kinds of doughnuts. How many different ways to select a dozen doughnuts? A ::= all selections of a dozen doughnuts Hint: define a bijection to some bit strings! 00 (none) Chocolate Lemon Sugar Glazed Plain

15 Counting Doughnut Selections A ::= all selections of a dozen doughnuts Define a bijection f between A and B Each doughnut is represented by a 0, and four 1’s are used to separate five types of doughnuts. B::= all 16-bit binary strings with exactly four 1’s. 00 (none) Chocolate Lemon Sugar Glazed Plain

16 Counting Doughnut Selections A ::= doughnuts selections B::= all 16-bit strings with four 1’s Chocolate Lemon Sugar Glazed Plain Chocolate Lemon Sugar Glazed Plain Chocolate Lemon Sugar Glazed Plain Chocolate Lemon Sugar Glazed Plain

17 Counting Doughnut Selections c chocolate, l lemon, s sugar, g glazed, p plain maps to 0 c 10 l 10 s 10 g 10 p B::= all 16-bit binary strings with exactly four 1’s. A ::= all selections of a dozen doughnuts This is a bijection because Two doughnut selections map to two different strings. (injection) (think of a doughnut selection as a sequence of 5 numbers (c,l,s,g,p), consider the first number which is different in the two sequences). Every string in B corresponds to a valid doughnut selection. (surjection)

18 Counting Doughnut Selections c chocolate, l lemon, s sugar, g glazed, p plain maps to 0 c 10 l 10 s 10 g 10 p B::= all 16-bit binary strings with exactly four 1’s. A ::= all selections of a dozen doughnuts

19 Counting Loops for i=1 to n do for j=1 to i do for k=1 to j do printf(“hello world\n”); How many “hello world” will this program print? B::= all strings with n-1 zeroes and 3 ones. A ::= all (i,j,k) triple

20 for i=1 to n do for j=1 to i do for k=1 to j do printf(“hello world\n”); … n … There are n possible values for the i,j,k. Imagine there are n-1 separators for the n values. If i=4, j=2, k=2, then there are two zeroes in 2 and one zero in 4. Counting Loops

21 for i=1 to n do for j=1 to i do for k=1 to j do printf(“hello world\n”); … n … Counting Loops In general, the position of the first zero corresponds to the value of k. The position of the second zero corresponds to the value of j. The position of the third zero corresponds to the value of i. k j i There are n possible values for the i,j,k.

22 for i=1 to n do for j=1 to i do for k=1 to j do printf(“hello world\n”); … n … This is a bijection (verify this!) between the values for i,j,k and the set of strings with n-1 ones and 3 zeros. So, the program prints “hello world” exactly times. Counting Loops There are n possible values for the i,j,k.

23 How many solutions are there to the equation x 1 +x 2 +x 3 +x 4 =10, where x 1,x 2,x 3,x 4 are nonnegative integers? Counting Non-Negative Integer Solutions B::= all 13-bit binary strings with exactly three 1’s. A ::= all non-negative integer solutions x 1 +x 2 +x 3 +x 4 =10 It is just like buying 10 doughnuts from 4 types. Think of there are 10 points to be distributed into 4 variables x 1 x 2 x 3 x 4 e.g. Suppose x 1 =3, x 2 =5, x 3 =2, x 4 =0, the 3 ones are used for separations.

24 How many solutions are there to the equation x 1 +x 2 +x 3 +x 4 =10, where x 1,x 2,x 3,x 4 are nonnegative integers? Counting Non-Negative Integer Solutions B::= all 13-bit binary strings with exactly three 1’s. A ::= all non-negative integer solutions x 1 +x 2 +x 3 +x 4 =10 It is just like buying 10 doughnuts from 4 types. It is not difficult to verify that this is a bijection, by the same argument as in doughnut selections. So, the are exactly integer solutions.

25 How many integer solutions to x 1 +x 2 +x 3 +x 4 =14 if each x i >=1? Set x i =y i +1. Consider the equation y 1 +y 2 +y 3 +y 4 =10 where each y i >=0. There is a bijection between the solutions for y and the solutions for x. Therefore we can apply the previous result, and conclude that the answer is Counting Positive Integer Solutions

26 How many integer solutions to x 1 +x 2 +x 3 +x 4 =0? Consider the equation y 1 +y 2 +y 3 +y 4 +y 5 =10 where each y i >=0. There is a bijection between the solutions for y and the solutions for x. Therefore we can apply the previous result, and conclude that the answer is because we need 4 ones and 10 zeroes. Counting Positive Integer Solutions

27 There are 20 books arranged in a row on a shelf. How many ways to choose 6 of these books so that no two adjacent books are selected? Choosing Non-Adjacent Books A ::= all selections of 6 non-adjacent books from 20 books B::= all 15-bit binary strings with exactly six 1’s.

28 A ::= all selections of 6 non-adjacent books from 20 books B::= all 15-bit binary strings with exactly six 1’s. Choosing Non-Adjacent Books Map each zero to a non-chosen book, each of the first five 1’s to a chosen book followed by a non-chosen book, and the last 1 to a chosen book. This is a bijection, because:  Two different selections are mapped to two different strings (injection) (consider the first position that is different in the two selections)  Every string in B corresponds to a valid selection (surjection)

29 Choosing Non-Adjacent Books A ::= all selections of 6 non-adjacent books from 20 books B::= all 15-bit binary strings with exactly six 1’s.

30 A ::= all selections of 6 non-adjacent books from 20 books B::= the set of integer solutions to x 1 +x 2 +x 3 +x 4 +x 5 +x 6 <=20 where x 1 >=1 and x 2,x 3,x 4,x 5,x 6 >=2. Choosing Non-Adjacent Books Here, each x i represents to pick the x i book after the previous chosen book. e.g. this configuration corresponds to x 1 =1, x 2 =4, x 3 =2, x 4 =5, x 5 =4, x 6 =4. It is not difficult to check that this is a bijection.

31 A ::= all selections of 6 non-adjacent books from 20 books B::= the set of integer solutions to x 1 +x 2 +x 3 +x 4 +x 5 +x 6 <=20 where x 1 >=1 and x 2,x 3,x 4,x 5,x 6 >=2. Choosing Non-Adjacent Books From slide 24 we learned that |B|=|C| for C::= the set of integer solutions to x 1 +x 2 +x 3 +x 4 +x 5 +x 6 <=9 where x 1,x 2,x 3,x 4,x 5,x 6 >=0. From slide 26 we learned that |C|=|D| for D::= the set of integer solutions to x 1 +x 2 +x 3 +x 4 +x 5 +x 6 +x 7 =9 where x 1,x 2,x 3,x 4,x 5,x 6,x 7 >=0. From slide 24 we learned that |D|=

32 Exercises What is the number of non-negative integer solutions to x 1 +x 2 +…+x m =n? What is the number of integer solutions to x 1 +x 2 +…+x m =n where x 1 >=a 1, x 2 >=a 2, …, and x m >=a m ? What is the number of integer solutions to x 1 +x 2 +…+x m <n where x 1 >=a 1, x 2 >=a 2, …, and x m >=a m ?

33 Exercises What is the number of non-negative integer solutions to x 1 +x 2 =n where x 1 <a 1 and x 2 <a 2 ? (Go to tutorial!) for i=1 to n do for j=1 to i-1 do for k=1 to j-1 do printf(“hello world\n”); How many “hello world” will this program print? (Hint 1: count the complement.) (Hint 2: inclusion-exclusion.)