1 More Counting by Mapping Lecture 16: Nov 7. 2 This Lecture Division rule Catalan number.

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

Rules of Matrix Arithmetic
10.1 Complex Numbers Definition:
Counting Chapter 6 With Question/Answer Animations.
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
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.
Recursion Lecture 18: Nov 18.
Functions, Pigeonhole Principle Lecture 14: Nov 4 A B f( ) =
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department.
CHAPTER 4 Decidability Contents Decidable Languages
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.
Counting II: Pascal, Binomials, and Other Tricks Great Theoretical Ideas In Computer Science A. Gupta D. Sleator CS Fall 2010 Lecture 8Sept. 16,
Copyright © Cengage Learning. All rights reserved.
Chapter 8 The principle of Inclusion and Exclusion Yen-Liang Chen Dept of Information Management National Central University.
Recursion Lecture 17: Nov 11. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do.
Set Theory A B C.
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.
Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,
Advanced Counting Techniques
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.
1 Permutations and Combinations CS/APMA 202 Rosen section 4.3 Aaron Bloomfield.
Chapter 6 The Inclusion-Exclusion Principle and Applications
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
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.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
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
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
1 Binomial Coefficients CS 202 Epp, section ??? Aaron Bloomfield.
COMPSCI 102 Discrete Mathematics for Computer Science.
Discrete Mathematics for Computer Science. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences Chapter 9 slides 1-54.
Great Theoretical Ideas in Computer Science.
Counting Techniques and Some Other Math Team Strategies Susan Schwartz Wildstrom Walt Whitman High School Bethesda, MD NCTM National Meeting April 6, 2001.
Week 6 - Friday.  What did we talk about last time?  Solving recurrence relations.
1 Counting by Mapping Lecture 15: Nov 4 A B …… f.
COMPSCI 102 Discrete Mathematics for Computer Science.
The Pigeonhole Principle. The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes,
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.
Section 3.2: Sequences and Summations. Def: A sequence is a function from a subset of the set of integers (usually the set of natural numbers) to a set.
CS 285- Discrete Mathematics
CS Lecture 8 Developing Your Counting Muscles.
SECTION 2 BINARY OPERATIONS Definition: A binary operation  on a set S is a function mapping S X S into S. For each (a, b)  S X S, we will denote the.
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.
Polynomials Count! CS Lecture 9 X1 X1 X2 X2 + + X3 X3.
August 2003 CIS102/LECTURE 9/FKS 1 Mathematics for Computing Lecture 9 LOGIC Chapter 3.
Permutations & Combinations: Selected Exercises. Copyright © Peter Cappello2 Preliminaries Denote the # of arrangements of some k elements of a set of.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Week 9 - Friday.  What did we talk about last time?  Permutations  Counting elements in sets  Brief introduction to combinations.
Fifteen Puzzle Move: can move a square adjacent to the empty square to the empty square.
1-1 Copyright © 2013, 2005, 2001 Pearson Education, Inc. Section 2.4, Slide 1 Chapter 2 Sets and Functions.
The Pigeonhole Principle
Developing Your Counting Muscles
CS100: Discrete structures
Basic Counting.
More Counting A B … f Lecture 16: Nov 9.
Counting Discrete Mathematics.
Basic Counting Lecture 9: Nov 5, 6.
Counting Techniques and Some Other Math Team Strategies
Counting II: Recurring Problems And Correspondences
Discrete Mathematics for Computer Science
Introduction to Discrete Mathematics
Counting II: Recurring Problems And Correspondences
Presentation transcript:

1 More Counting by Mapping Lecture 16: Nov 7

2 This Lecture Division rule Catalan number

3 If a function from A to B is k-to-1, meaning that each element in B is mapped by exactly k elements in A then (This generalizes the Bijection Rule.) Division Rule e.g. This is a 2-to-1 function. So # of ears = 2 x # of people.

4 Example 3: Two Pairs Double Count! This is something we have encountered before when we counted poker hands. A: the set of two pairs B: the set of sequences which satisfy (1)-(6). What we did was to show that the mapping from A to B is 1-to-2, and thus conclude that 2|A| = |B|. Then we compute |B| and then |A|. (See L2 slide 36 for details.)

5 Another Chess Problem In how many different ways can you place two identical rooks on a chessboard so that they do not share a row or column?

6 We define a mapping between configurations to sequences (r(1), c(1), r(2), c(2)), where r(1) and r(2) are distinct rows, and c(1) and c(2) are distinct columns. Another Chess Problem A ::= all sequences (r(1),c(1),r(2),c(2)) with r(1) ≠ r(2) and c(1) ≠ c(2) B::= all valid rook configurations (1,1,8,8) and (8,8,1,1) maps to the same configuration. The mapping is a 2-to-1 mapping.

7 Another Chess Problem A ::= all sequences (r(1),c(1),r(2),c(2)) with r(1) ≠ r(2) and c(1) ≠ c(2) B::= all valid rook configurations The mapping is a 2-to-1 mapping. Using the generalized product rule to count |A|, there are 8 choices of r(1) and c(1), there are 7 choices of r(2) and c(2), and so |A| = 8x8x7x7 = Thus, total number of configurations |B| = |A|/2 = 3136/2 = 1568.

8 How many ways can we seat n different people at a round table? Round Table Two seatings are considered equivalent if one can be obtained from the other by rotation. equivalent

9 A ::= all the permutations of the people B::= all possible seating arrangements at the round table Round Table Map each permutation in set A to a circular seating arrangement in set B by following the natural order in the permutation.

10 Round Table A ::= all the permutations of the people B::= all possible seating arrangements at the round table This mapping is an n-to-1 mapping. Thus, total number of seating arrangements |B| = |A|/n = n!/n = (n-1)!

11 Counting Subsets How many size 4 subsets of {1,2,…,13}? Let A::= permutations of {1,2,…,13} B::= size 4 subsets map a 1 a 2 a 3 a 4 a 5 … a 12 a 13 to {a 1,a 2,a 3, a 4 } (that is, take the first k elements from the permutation) How many permutations are mapped to the same subset?? Now we can use the division rule to compute more formally.

12 map a 1 a 2 a 3 a 4 a 5 … a 12 a 13 to {a 1,a 2,a 3, a 4 } a 2 a 4 a 3 a 1 a 5 … a 12 a 13 also maps to {a 1,a 2,a 3, a 4 } as does a 2 a 4 a 3 a 1 a 13 a 12 … a 5 So this mapping is 4!  9!-to-1 Counting Subsets 4! 9! Any ordering of the first four elements (4! of them), and also any ordering of the last nine elements (9! of them) will give the same subset.

13 Let A::= permutations of {1,2,…,13} B::= size 4 subsets Counting Subsets So number of 4 element subsets is Number of m element subsets of an n element set is

14 MISSISSIPPI How many ways to rearrange the letters in the word “MISSISSIPPI”? Let A be the set of all permutations of n letters. B be the set of all different words by rearranging “MISSISSIPPI”. How many permutations are mapped to the same word? MISSISSIPPI 4! possible ways to rearrange the S giving the same word 4! possible ways to rearrange the I giving the same word 2! possible ways to rearrange the P giving the same word The mapping is 4!4!2!-to-1, and so there are 11!/4!4!2! different words.

15 I’m planning a 20-mile walk, which should include 5 northward miles, 5 eastward miles, 5 southward miles, and 5 westward miles. How many different walks are possible? There is a bijection between such walks and words with 5 N’s, 5 E’s, 5 S’s, and 5 W’s. The number of such words is equal to the number of rearrangements: 20! 5!5!5!5! Example: 20 Mile Walk

16 What is the coefficient of x 7 y 9 z 5 in (x+y+z) 21 ? There are 12 people. How many ways to divide them into 3 teams, each team with 4 people? Exercises

17 This Lecture Division rule Catalan number

18 Monotone Path A monotone path from (0,0) to (n,n) is a path consist of “right" moves (x-coordinate increase by 1) and “up" moves (y-coordinate increase by 1), starting at (0,0) and ending at (n,n). How many possible monotone paths from (0,0) to (n,n)? We can map a “right” move to an “x” and a “up” move to a “y”. There is a bijection between monotone paths and words with n x’s and n y’s. And so the answer is just

19 Monotone Path We say such a path “lower-right" monotone path if all of the points (x i,y i ) on the path has x i >= y i. lower-right monotoneNOT lower-right monotone How many possible lower right monotone paths from (0,0) to (n,n)?

20 Monotone Path How many possible lower right monotone paths from (0,0) to (n,n)? We can still map a “right” move to an “x” and a “up” move to a “y”. There is a bijection between (A) lower right monotone paths and (B) words with n x’s and n y’s, with the additional constraint that no initial segment of the string has more Y's than X's. The set (B) is called the set of Dyck words. There is a bijection, but both sets look difficult to count.

21 Parenthesis How many valid ways to add n pairs of parentheses? ((())) (()()) (())() ()(()) ()()() E.g. There are 5 valid ways to add 3 pairs of parentheses. Let r n be the number of ways to add n pairs of parentheses. A pairing is valid if and only if there are at least as many open parentheses than close parentheses from the left.

22 Mountain Ranges How many “mountain ranges” can you form with n upstrokes and n downstrokes that all stay above the original line? /\ /\ /\ /\/\ / \ /\/\/\, /\/ \, / \/\, / \, / \ We do not know how to solve these three problems yet, (A) lower right monotone paths, (B) Dyck words, (C) valid parentheses, (D) mountain ranges. But we can show that all these three problems have the same answer, by showing that there are bijections between these sets.

23 Parenthesis and Monotone Paths (()()()) ()()()() A pairing is valid if and only if there are at least as many open parentheses than close parentheses from the left. We can map a “(” to an “x” and a “)” move to a “y”. There is a bijection between (C) valid pairings and (B) Dyck words. In slide 19, we have seen that there is a bijection between (A) lower right monotone paths and (B) Dyck words. So, there is a bijection between (A) and (C). xxyxyxyyxyxyxyxy

24 Parenthesis and Monotone Paths (()()()) ()()()() A pairing is valid if and only if there are at least as many open parentheses than close parentheses from the left. A monotone path is “lower-right” if and only if there are at least as many right moves than up moves from the starting point. So there is a bijection between these two sets (A) and (C) by each open parenthesis with a right move and a close parenthesis by an up move.

25 Monotone Paths and Mountain Ranges By “rotating” the images, we see that a path not crossing the diagonal is just the same as a mountain not crossing the horizontal line. So there is a bijection between (A) and (D).

26 Catalan Number Now we know that these three sets are of equal size, although we don’t know the size. It turns out that the answer is exactly This is called the nth Catalan number, and has applications in many other places as well. One proof of this formula is by the bijective rule.

27 Proof Plan The number of lower right monotone paths from (0,0) to (n,n) is The plan is to count the complement. In slide 18, we know that the number of monotone paths is We will show that the number of non-lower-right monotone paths is This would imply that the number of lower-right monotone paths is

28 Proof The number of non-lower-right monotone paths is The idea is to define a bijection between (A) The set of non-lower-right monotone paths from (0,0) to (n,n) (B) The set of monotone paths from (0,0) to (n-1,n+1) Clearly, the size of (B) is equal to, as it is equal to the set of strings with 2n characters, where n-1 of them are R (“right”) and n+1 of them are U (“up”). So, it remains to define a bijection between (A) and (B).

29 Bijection Every path in (A) must “cross” the diagonal at least once. We look at the first “crossing”, and then “flip the path”. (picture from wiki) In the original path, before the flipping point, we have one more U than R. So, in the original path, after the flipping point, we have one more R than U. In the new path, since we flip the latter part, we have two more U than R, and thus it is a path from (0,0) to (n-1,n+1).

30 Bijection Every path in (A) must “cross” the diagonal at least once. We look at the first “crossing”, and then “flip the path”. (picture from wiki) The easiest way to see that this is a bijection is to define the inverse function. Given a monotone path from (0,0) to (n-1,n+1), it must cross the diagonal. Look at the first point and flip it, we get back the non-lower-right monotone path from (0,0) to (n,n) that was mapped to it.

31 Catalan Number The “reflection” technique in the proof is useful in some other problems. Perhaps you may see it again in homeworks. There are other proofs and other applications of Catalan number (see wiki).

32 Quick Summary Counting by mapping is a very useful technique. It is also a powerful technique to solve more complicated problems. The basic examples usually map a set into a properly defined binary strings. Then we see how to generalize this approach by considering k-to-1 functions. Finally we see the mapping between more complicated sets. Anyway, the idea of define a mapping (reduction) between two problems is probably the most important idea in computer science. So, make sure you are familiar with it.

33 Mapping Between Infinite Sets (Optional) How to compare the size of two infinite sets? Cantor proposed an elegant defintion: Two infinite sets are “equal” if there is a bijection between them. Using this definition, it can be shown that: The set of positive integers = the set of integers The set of integers = the set of rational numbers The set of integers ≠ the set of real numbers The idea can be applied to CS, see page of the textbook.