Copyright © Zeph Grunschlag, 2001-2002. Counting Techniques Zeph Grunschlag.

Slides:



Advertisements
Similar presentations
Lecture 4 4.1,4.2 Counting. 4.1 Counting Two Important Principles: Product Rule and Sum Rule. Product Rule: Assume we need to perform procedure 1 AND.
Advertisements

COUNTING AND PROBABILITY
Recursively Defined Functions
The Pigeonhole Principle
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.
after UCI ICS/Math 6A, Summer Counting-1 Counting: Product and Sum Rules Product Rule: Assuming a)We need to.
3.3 The Characteristic function of the set  function from universal set to {0,1}  Definition 3.6: Let U be the universal set, and let A  U. The characteristic.
Lecture 14: Oct 28 Inclusion-Exclusion Principle.
1 Section 1.7 Set Operations. 2 Union The union of 2 sets A and B is the set containing elements found either in A, or in B, or in both The denotation.
1 Section 4.1 Basics of Counting. 2 Basic Counting Principles: Sum Rule Suppose you have two tasks to perform: –The first task can be done in n 1 ways;
CS5371 Theory of Computation
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
CSE115/ENGR160 Discrete Mathematics 04/10/12
Copyright © Zeph Grunschlag, Set Operations Zeph Grunschlag.
1 Copyright M.R.K. Krishna Rao 2003 Ch 4. Counting Techniques Counting techniques are important in programming design. EG: How large an array or hash table.
Pigeonhole.
Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
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.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Cardinality of Sets Section 2.5.
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Binomial Coefficients, Inclusion-exclusion principle
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
September1999 CMSC 203 / 0201 Fall 2002 Week #8 – 14/16 October 2002 Prof. Marie desJardins.
3. Counting Permutations Combinations Pigeonhole principle Elements of Probability Recurrence Relations.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Section Section Summary The Product Rule The Sum Rule The Subtraction Rule The Division Rule Examples, Examples, and Examples Tree Diagrams.
CS201: Data Structures and Discrete Mathematics I
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
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 Techniques. L172 Agenda Section 4.1: Counting Basics Sum Rule Product Rule Inclusion-Exclusion.
Fall 2008/2009 I. Arwa Linjawi & I. Asma’a Ashenkity 11 Basic Structure : Sets, Functions, Sequences, and Sums Sets Operations.
Counting Discrete Mathematics. Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter passwords are there?”
1 Section 3.3 Principle of Inclusion and Exclusion.
Discrete Structures Li Tak Sing ( 李德成 ) Lectures
Sets Definition: A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a.
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 7 Functions Instructor: Hayk Melikyan Today we will review sections 7.3, 7.4 and 7.5.
1 Chapter 2 Pigeonhole Principle. 2 Summary Pigeonhole principle –simple form Pigeonhole principle –strong form Ramsey’s theorem.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
1 The Pigeonhole Principle CS 202 Epp section 7.3.
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.
Introduction Suppose that a password on a computer system consists of 6, 7, or 8 characters. Each of these characters must be a digit or a letter of the.
The Pigeonhole Principle Alan Kaylor Cline. The Pigeonhole Principle Statement Children’s Version: “If k > n, you can’t stuff k pigeons in n holes without.
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.
The Pigeonhole Principle. Pigeonhole principle The pigeonhole principle : If k is a positive integer and k+1 or more objects are placed into k boxes,
Pigeonhole Principle. If n pigeons fly into m pigeonholes and n > m, then at least one hole must contain two or more pigeons A function from one finite.
Main Menu Main Menu (Click on the topics below) Pigeonhole Principle Example Generalized Pigeonhole Principle Example Proof of Pigeonhole Principle Click.
Permutations & Combinations: Selected Exercises. Copyright © Peter Cappello2 Preliminaries Denote the # of arrangements of some k elements of a set of.
Section The Product Rule  Example: How many different license plates can be made if each plate contains a sequence of three uppercase English letters.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Principle of Inclusion and Exclusion
Copyright © Zeph Grunschlag,
CSC 321: Data Structures Fall 2015 Counting and problem solving
Copyright © Zeph Grunschlag,
The Pigeonhole Principle
Discrete Structures for Computer Science
COCS DISCRETE STRUCTURES
CSC 321: Data Structures Fall 2016 Counting and proofs
Copyright © Zeph Grunschlag,
Recursively Defined Functions
CS100: Discrete structures
Set, Combinatorics, Probability & Number Theory
COUNTING AND PROBABILITY
Representations of Integers
Copyright © Zeph Grunschlag,
Copyright © Zeph Grunschlag,
The Pigeonhole Principle
Presentation transcript:

Copyright © Zeph Grunschlag, Counting Techniques Zeph Grunschlag

L172 Agenda Section 4.1: Counting Basics Sum Rule Product Rule Inclusion-Exclusion Section 4.2 Basic pigeonhole principle Generalized pigeonhole principle

L173 Counting Basics Counting techniques are important in programming design. EG: How large an array or hash table or heap is needed? EG: What is the average case complexity of quick-sort? Answers depend on being able to count. Counting is useful in the gambling arena also. EG: What should your poker strategy be?

L174 Counting Basics Set Cardinalities Interested in answering questions such as: How many bit strings of length n are there? How many ways are there to buy 13 different bagels from a shop that sells 17 types? How many bit strings of length 11 contain a streak of one type of bit of exact length 7? How many ways can a dating service match 13 men to 17 women? COMMON THEME: convert to set cardinality problems so each question above is a about counting the number of elements in some set: Q: What is the corresponding set in each case?

L175 Counting Basics Set Cardinalities A: The set to measure the cardinality of is… How many bit strings of length n are there? {bit strings of length n} How many ways are there to buy 13 different bagels from a shop that sells 17 types? {S  {1, 2, … 17} | |S | = 13 } (…arguable) How many bit strings of length 11 contain a streak of one type of bit of exact length 7? {length 11 bit strings with 0-streak of length 7}  {length 11 bit strings with 1-streak of length 7} How many ways to match 13 M to 17 W ? { f :{1,2,…,13}  {1,2,…,17} | f is 1-to-1}

L176 Product Rule As counting problems can be turned into set cardinality problems, useful to express counting principles set theoretically. Product-Rule: For finite sets A, B: |A  B| = |A|  |B| Q: How many bit strings of length n are there?

L177 Product Rule A: 2 n. Proof : Let S = {bit strings of length n}. S is in 1-to-1 correspondence with Consequently the product rule implies:

L178 Cardinality of Power Set THM: |P ({1,2,3,…,n})| = 2 n Proof. The set of bit strings of length n is in 1-to-1 correspondence with the P({1,2,3,…,n}) since subsets are represented by length n bit strings.

L179 Sum Rule Next the number of length 11 bit strings with a streak of length exactly 7. Q: Which of the following should be counted:

L1710 Sum Rule Next the number of length 11 bit strings with a streak of length exactly 7. Q: Which of the following should be counted: No!, longest streak has length No! Too long No! Streak too long Yes! Yes!

L1711 Sum Rule We are trying to compute the cardinality of: {length 11 bit strings with 0-streak of length 7}  {length 11 bit strings with 1-streak of length 7} Call the first set A and the second set B. Q: Are A and B disjoint?

L1712 Sum Rule A: Yes. If had both a 0-streak and a 1-streak of length 7 each, string would have length at least 14! When counting the cardinality of a disjoint union we use: SUM RULE: If A and B are disjoint, then |A  B| = |A|+|B| By symmetry, in our case A and B have the same cardinality. Therefore the answer would be 2|A|.

L1713 Sum Rule Break up A = {length 11 bit strings with 0-streak of length exactly 7} into more cases and use sum rule: A 1 = { ***} (* is either 0 or 1) A 2 = { **} A 3 = {* *} A 4 = {** } A 5 = {*** }. Apply sum rule: |A| = |A 1 | +|A 2 | +|A 3 | +|A 4 | +|A 5 |

L1714 Sum Rule So let’s count each set. A 1 = { ***}. There are 3 *’s, each with 2 choices, so product rule gives |A 1 | = 2 3 = 8 A 2 = { **}. There are 2 *’s. Therefore, |A 2 | = 2 2 = 4 A 3 = {* *}, A 4 = {** } Similarly: |A 2 | = |A 3 | = |A 4 | = 4 A 5 = {*** }. |A 1 | = |A 5 | = 8 |A| = |A 1 | +|A 2 | +|A 3 | +|A 4 | +|A 5 | = = 28. Therefore answer is 56.

L1715 Counting Functions How many ways to match 13M to 17W ? { f :{1,2,…,13}  P {1,2,…,17} | f is 1-to-1} Use product rule thoughtfully possible output values for f (1) values remain for f (2) …………………………… i. 17-i+1 values remain for f (i ) …………………………… =5 values remain for f (13) ANS: 17·16·15 ·14 ·… ·7·6·5 = 17! / 4! Q: In general how many 1-to-1 functions from size k to size n set?

L1716 Counting Functions A: The number of 1-to-1 functions from a size k set to a size n set is n ! / (n - k) ! As long as k is no larger than n. If k > n there are no 1-to-1 functions. Q: How about general functions from size k sets to size n sets?

L1717 Counting Functions A: The number of functions from a size k set to a size n set is n k

L1718 Inclusion-Exclusion The principle of Inclusion-Exclusion generalized the sum rule the the case of non-empty intersection: INCLUSION-EXCLUSION: If A and B are sets, then |A  B | = |A|+|B |- |A  B | This says that when counting all the elements in A or B, if we just add the the sets, we have double-counted the intersection, and must therefore subtract it out.

L1719 Inclusion-Exclusion Visualize. Diagram gives proof Inclusion- Exclusion principle: A-A  B U ABAB B-A  B

L1720 Blackboard Exercises for Section 4.1 Problem (a,b,c,f). How many positive integers with exactly three decimal digits are… …divisible by 7? …odd? …have the same 3 digits? …are not divisible by 3 or 4? Problem How many ways can the letters a,b,c,d be arranged such that a is not immediately followed by b? Link to worked out problems

L The Pigeonhole Principle The pigeonhole principle is the (rather obvious) statement: If there are n+1 pigeons, which must fit into n pigeonholes then some pigeonhole contains 2 or more pigeons. Less obvious: Why this would ever be useful… Principle often applied in surprising ways.

L1722 Pigeonhole Principle EG: Given 12 or more numbers between 0 and 1 inclusive, there are 2 (or more) numbers x,y whose strictly within 0.1 of each other. Proof. Any pigeonhole principle application involves discovering who are the pigeons, and who are the pigeonholes. In our case: Pigeons: The 12 numbers Pigeonholes: The sets [0,0.1), [0.1,0.2), [0.2,0.3), …,[0.9,1), {1} There are 11 pigeonholes so some x,y fall in one of these sets, and have difference < 0.1

L1723 Pigeonhole Principle Harder Example: In a party of 2 or more people, there are 2 people with the same number of friends in the party. (Assuming you can’t be your own friend and that friendship is mutual.) Proof. Pigeons –the n people (with n > 1). Pigeonholes –the possible number of friends. I.e. the set {0,1,2,3,…n-1}

L1724 Pigeonhole Principle The proof proceeds with 2 cases. I) There is a pigeonhole which isn’t hit. In that case, left with n -1 remaining pigeonholes, but n pigeons, so done. II) Every pigeonhole hit. In particular, the friendship numbers n-1 as well as 0 were hit. Thus someone is friends with everyone while someone else is friends with no-one. This is a contradiction so this case cannot happen!  

L1725 Generalized Pigeonhole Principle If N objects are placed into k boxes, there is at least one box containing  N/k  objects. Specialize to N = n+1 and k = n, gives at least  (n+1)/n  = 2 objects in one box, which is the regular pigeonhole principle. Q: Suppose that NYC has more than 7,000,000 inhabitants and that the human head contains at most 500,000 hairs. Find a guaranteed minimum number of people in NYC that all have the same number of hairs on their heads.

L1726 Generalized Pigeonhole Principle A:  7,000,000 / 500,001  = 14

L1727 Blackboard Exercises for Section Show that if S  {1,2,3,…,50} & |S |> 9 then there are at least 2 different 5 element subsets in S all having the same sum. 2. Problem : There are 38 different time periods during which classes at a university can be scheduled. If there are 677 different classes, how many different rooms will be needed? Link to worked out problems