11.1 CompSci 102© Michael Frank Today’s topics CountingCounting –Sum rule –Product rule –Tree diagrams –Inclusion/exclusion Reading: Sections 4.1Reading:

Slides:



Advertisements
Similar presentations
Counting Chapter 6 With Question/Answer Animations.
Advertisements

Recursive Definitions and Structural Induction
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.
Advanced Counting Techniques Prof. Johnnie Baker
1 Combinatorics Rosen 6 th ed., § , § Combinatorics Count the number of ways to put things together into various combinations.Count the number.
1 Discrete Math CS 2800 Prof. Bart Selman Module Counting Chapter 5, Rosen.
Today Today: Reading: –Read Chapter 1 by next Tuesday –Suggested problems (not to be handed in): 1.1, 1.2, 1.8, 1.10, 1.16, 1.20, 1.24, 1.28.
Lecture 14: Oct 28 Inclusion-Exclusion Principle.
Copyright © Zeph Grunschlag, Counting Techniques Zeph Grunschlag.
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;
CSE115/ENGR160 Discrete Mathematics 04/10/12
Combinations We should use permutation where order matters
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
CS100 : Discrete Structures
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Counting Chapter 6 With Question/Answer Animations.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Discrete Maths Objective to introduce some of the counting rules (product, sum, subtraction, division, pigeonhole) through examples , Semester 2,
Counting. Why counting  Determine the complexity of algorithms To sort n numbers, how many instructions are executed ?  Count the number of objects.
The Basics of Counting Section 6.1.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
9.3 Addition Rule. The basic rule underlying the calculation of the number of elements in a union or difference or intersection is the addition rule.
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Chapter 3 Permutations and combinations
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
3. Counting Permutations Combinations Pigeonhole principle Elements of Probability Recurrence Relations.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Lesson Counting Techniques. Objectives Solve counting problems using the Multiplication Rule Solve counting problems using permutations Solve counting.
1 CSC 321: Data Structures Fall 2013 Counting and problem solving  mappings, bijection rule  sequences, product rule, sum rule  generalized product.
The Basics of Counting Section 6.1.
Section Section Summary The Product Rule The Sum Rule The Subtraction Rule The Division Rule Examples, Examples, and Examples Tree Diagrams.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/37 Module.
Module #15: Combinatorics Rosen 5 th ed., §§ & §6.5 Now we are moving on to Ch. 4 It is the study of arrangement of objects e.g. enumeration, counting.
CSNB143 – Discrete Structure
Counting Techniques. L172 Agenda Section 4.1: Counting Basics Sum Rule Product Rule Inclusion-Exclusion.
CS 103 Discrete Structures Lecture 16
Main Menu Main Menu (Click on the topics below) Combinatorics Introduction Equally likely Probability Formula Counting elements of a list Counting elements.
Counting.
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 7 Functions Instructor: Hayk Melikyan Today we will review sections 7.3, 7.4 and 7.5.
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.
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.
CS 104: Discrete Mathematics
Main Menu Main Menu (Click on the topics below) Pigeonhole Principle Example Generalized Pigeonhole Principle Example Proof of Pigeonhole Principle Click.
Chapter 6 With Question/Answer Animations Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
11.1 CompSci 102© Michael Frank Today’s topics CountingCounting –Generalized Pigeonhole Principle –Permutations –Combinations –Binomial Coefficients –Writing.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
CSC 321: Data Structures Fall 2015 Counting and problem solving
ICS 253: Discrete Structures I
Today’s topics Counting Reading: Sections , 4.4 Upcoming
Discrete Structures for Computer Science
COCS DISCRETE STRUCTURES
CSC 321: Data Structures Fall 2016 Counting and proofs
CS100: Discrete structures
Discrete Structures for Computer Science
Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011
Module #15: Combinatorics
COUNTING AND PROBABILITY
Discrete Mathematics and its Applications
Module #15: Combinatorics
Representations of Integers
Discrete Mathematics and its Applications
Presentation transcript:

11.1 CompSci 102© Michael Frank Today’s topics CountingCounting –Sum rule –Product rule –Tree diagrams –Inclusion/exclusion Reading: Sections 4.1Reading: Sections 4.1 UpcomingUpcoming –Permutations & Combinations

11.2 CompSci 102© Michael Frank Combinatorics The study of the number of ways to put things together into various combinations.The study of the number of ways to put things together into various combinations. E.g. In a contest entered by 100 people,E.g. In a contest entered by 100 people, –how many different top-10 outcomes could occur? E.g. If a password is 6-8 letters and/or digits,E.g. If a password is 6-8 letters and/or digits, –how many passwords can there be?

11.3 CompSci 102© Michael Frank Sum and Product Rules (§4.1) Let m be the number of ways to do task 1 and n the number of ways to do task 2,Let m be the number of ways to do task 1 and n the number of ways to do task 2, –with each number independent of how the other task is done, –and also assume that no way to do task 1 simultaneously also accomplishes task 2. Then, we have the following rules:Then, we have the following rules: –The sum rule: The task “do either task 1 or task 2, but not both” can be done in m+n ways. –The product rule: The task “do both task 1 and task 2” can be done in mn ways.

11.4 CompSci 102© Michael Frank Set Theoretic Version If A is the set of ways to do task 1, and B the set of ways to do task 2, and if A and B are disjoint, then:If A is the set of ways to do task 1, and B the set of ways to do task 2, and if A and B are disjoint, then: –The ways to do either task 1 or 2 are A  B, and |A  B|=|A|+|B| –The ways to do both task 1 and 2 can be represented as A  B, and |A  B|=|A|·|B|

11.5 CompSci 102© Michael Frank IP Address Example Some facts about the Internet Protocol, version 4:Some facts about the Internet Protocol, version 4: –Valid computer addresses are in one of 3 types: A class A IP address contains a 7-bit “netid” ≠ 1 7, and a 24-bit “hostid”A class A IP address contains a 7-bit “netid” ≠ 1 7, and a 24-bit “hostid” A class B address has a 14-bit netid and a 16-bit hostid.A class B address has a 14-bit netid and a 16-bit hostid. A class C addr. Has 21-bit netid and an 8-bit hostid.A class C addr. Has 21-bit netid and an 8-bit hostid. –The 3 classes have distinct headers (0, 10, 110) –Hostids that are all 0s or all 1s are not allowed. How many valid computer addresses are there?How many valid computer addresses are there? e.g., duke.edu is

11.6 CompSci 102© Michael Frank IP address solution (# addrs) = (# class A) + (# class B) + (# class C)(# addrs) = (# class A) + (# class B) + (# class C) (by sum rule) # class A = (# valid netids)·(# valid hostids)# class A = (# valid netids)·(# valid hostids) (by product rule) (# valid class A netids) = 2 7 − 1 = 127.(# valid class A netids) = 2 7 − 1 = 127. (# valid class A hostids) = 2 24 − 2 = 16,777,214.(# valid class A hostids) = 2 24 − 2 = 16,777,214. Continuing in this fashion we find the answer is: 3,737,091,842 (3.7 billion IP addresses)Continuing in this fashion we find the answer is: 3,737,091,842 (3.7 billion IP addresses)

11.7 CompSci 102© Michael Frank Inclusion-Exclusion Principle (§§4.1 & 6.5) Suppose that k  m of the ways of doing task 1 also simultaneously accomplish task 2.Suppose that k  m of the ways of doing task 1 also simultaneously accomplish task 2. –And thus are also ways of doing task 2. Then, the number of ways to accomplish “Do either task 1 or task 2” is m  n  k.Then, the number of ways to accomplish “Do either task 1 or task 2” is m  n  k. Set theory: If A and B are not disjoint, then |A  B|=|A|  |B|  |A  B|.Set theory: If A and B are not disjoint, then |A  B|=|A|  |B|  |A  B|. –If they are disjoint, this simplifies to |A|+|B|.

11.8 CompSci 102© Michael Frank Inclusion/Exclusion Example Some hypothetical rules for passwords:Some hypothetical rules for passwords: –Passwords must be 2 characters long. –Each character must be a letter a-z, a digit 0-9, or one of the 10 punctuation characters –Each password must contain at least 1 digit or punctuation character.

11.9 CompSci 102© Michael Frank Setup of Problem A legal password has a digit or puctuation character in position 1 or position 2.A legal password has a digit or puctuation character in position 1 or position 2. –These cases overlap, so the principle applies. (# of passwords w. OK symbol in position #1) = (10+10)·( )(# of passwords w. OK symbol in position #1) = (10+10)·( ) (# w. OK sym. in pos. #2): also 20·46(# w. OK sym. in pos. #2): also 20·46 (# w. OK sym both places): 20·20(# w. OK sym both places): 20·20 Answer:Answer:

11.10 CompSci 102© Michael Frank Pigeonhole Principle (§4.2) A.k.a. the “Dirichlet drawer principle”A.k.a. the “Dirichlet drawer principle” If ≥k+1 objects are assigned to k places, then at least 1 place must be assigned ≥2 objects.If ≥k+1 objects are assigned to k places, then at least 1 place must be assigned ≥2 objects. In terms of the assignment function:In terms of the assignment function: –If f:A→B and |A|≥|B|+1, then some element of B has ≥2 preimages under f. I.e., f is not one-to-one.I.e., f is not one-to-one.

11.11 CompSci 102© Michael Frank Example of Pigeonhole Principle There are 101 possible numeric grades (0%- 100%) rounded to the nearest integer.There are 101 possible numeric grades (0%- 100%) rounded to the nearest integer. –Also, there are >101 students in this class. Therefore, there must be at least one (rounded) grade that will be shared by at least 2 students at the end of the semester.Therefore, there must be at least one (rounded) grade that will be shared by at least 2 students at the end of the semester. –I.e., the function from students to rounded grades is not a one-to-one function.

11.12 CompSci 102© Michael Frank Fun Pigeonhole Proof (Ex. 4, p.314) Theorem:  n  N,  a multiple m>0 of n  m has only 0’s and 1’s in its decimal expansion!Theorem:  n  N,  a multiple m>0 of n  m has only 0’s and 1’s in its decimal expansion! Proof: Consider the n+1 decimal integers 1, 11, 111, …, 1  1. They have only n possible residues mod n. So, take the difference of two that have the same residue. The result is the answer! □Proof: Consider the n+1 decimal integers 1, 11, 111, …, 1  1. They have only n possible residues mod n. So, take the difference of two that have the same residue. The result is the answer! □ n+1

11.13 CompSci 102© Michael Frank A Specific Case Let n=3. Consider 1, 11, 111, 1111.Let n=3. Consider 1, 11, 111, –1 mod 3 = 1 –11 mod 3 = 2 –111 mod 3 = 0  Lucky extra solution. –1,111 mod 3 = 1 1,111 − 1 = 1,110 = 3·370.1,111 − 1 = 1,110 = 3·370. –It has only 0’s and 1’s in its expansion. –Its residue mod 3 = 0, so it’s a multiple of 3. Note same residue.

11.14 CompSci 102© Michael Frank Another Fun Example Suppose that next June, the Durham Bulls play at least 1 game a day, but ≤45 games total. Show there must be some sequence of consecutive days in June during which they play exactly 14 games.Suppose that next June, the Durham Bulls play at least 1 game a day, but ≤45 games total. Show there must be some sequence of consecutive days in June during which they play exactly 14 games. –Proof: Let a j be the number of games played on or before day j. Then, a 1,…,a 30  Z + is a sequence of 30 distinct integers with 1 ≤ a j ≤ 45. Therefore a 1 +14,…,a is a sequence of 30 distinct integers with 15 ≤ a j +14 ≤ 59. Thus, (a 1,…,a 30,a 1 +14,…,a ) is a sequence of 60 integers from the set {1,..,59}. By the Pigeonhole Principle, two of them must be equal, but a i ≠a j for i≠j. So,  ij: a i = a j +14. Thus, 14 games were played on days a j +1, …, a i.

11.15 CompSci 102© Michael Frank Baseball problem illustrated Example of {a i }: Note all elements are distinct.Example of {a i }: Note all elements are distinct. –1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 23, 25, 27, 29, 30, 31, 33, 34, 36, 37, 39, 40, 41, 43, 45 –Then {a i +14} is the following sequence: 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 32, 33, 35, 36, 37, 39, 41, 43, 44, 45, 47, 48, 50, 51, 53, 54, 55, 57, 59 In any 60 integers from 1-59 there must be some duplicates, indeed we find the following ones:In any 60 integers from 1-59 there must be some duplicates, indeed we find the following ones: –16, 19, 21, 22, 25, 27, 30, 33, 36, 37, 39, 41, 43, 45 Thus, for example, exactly 14 games were played during days 3 to 11: