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;

Slides:



Advertisements
Similar presentations
Basic Counting Rosen 4.1. Sum Rule If a first task can be done in n 1 ways and a second task can be done in n 2 ways, and if these tasks cannot be done.
Advertisements

Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
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.
College of Information Technology & Design
Chapter 6 With Question/Answer Animations. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Counting and Probability The outcome of a random process is sure to occur, but impossible to predict. Examples: fair coin tossing, rolling a pair of dice,
Chapter 7 Logic, Sets, and Counting Section 3 Basic Counting Principles.
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.
Copyright © Zeph Grunschlag, Counting Techniques Zeph Grunschlag.
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.
Advanced Counting Techniques
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications (5 th edition) Kenneth H. Rosen Chapter 4 Counting.
CS100 : Discrete Structures
4. Counting 4.1 The Basic of Counting Basic Counting Principles Example 1 suppose that either a member of the faculty or a student in the department is.
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
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 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Generalized Permutations and Combinations
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.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
1 Lecture 4 (part 1) Combinatorics Reading: Epp Chp 6.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
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.
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.
Counting Techniques. L172 Agenda Section 4.1: Counting Basics Sum Rule Product Rule Inclusion-Exclusion.
CS 103 Discrete Structures Lecture 16
11.1 CompSci 102© Michael Frank Today’s topics CountingCounting –Sum rule –Product rule –Tree diagrams –Inclusion/exclusion Reading: Sections 4.1Reading:
1 Basics of Counting CS/APMA 202 Rosen section 4.1 Aaron Bloomfield.
Discrete Structures Counting (Ch. 6)
1 Section 6.5 Inclusion/Exclusion. 2 Finding the number of elements in the union of 2 sets From set theory, we know that the number of elements in the.
Introduction to Discrete Probability Epp, section 6.x CS 202.
Counting Principles Multiplication rule Permutations Combinations.
Counting.
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
Chapter 6 With Question/Answer Animations Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 5 Counting 歐亞書局.
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.
ICS 253: Discrete Structures I
Chapter 5, Section 5.1 The Basics of Counting
Copyright © Zeph Grunschlag,
The Pigeonhole Principle
Discrete Structures for Computer Science
COCS DISCRETE STRUCTURES
Copyright © Zeph Grunschlag,
Counting Chapter 6 With Question/Answer Animations
Recursively Defined Functions
CS100: Discrete structures
Discrete Structures for Computer Science
Module #15: Combinatorics
Module #15: Combinatorics
Representations of Integers
Discrete Mathematics and its Applications
Copyright © Zeph Grunschlag,
Copyright © Zeph Grunschlag,
Presentation transcript:

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; –The second task can be done in n 2 ways; –If the two tasks can’t be done simultaneously, then there are n 1 + n 2 ways to do either task Application of sum rule is pretty obvious: add up the number of variations to arrive at the total, which is your answer Can be extended to more than 2 tasks

3 Example 1 (using sum rule) Suppose one CS major or one engineering major is eligible for the prestigious Sheller scholarship Suppose there are 20 CS majors and 15 engineering majors to choose from - how many choices are there for the scholarship? = 35 possible choices

4 Example 2 (using sum rule) What is the value of k after the following code is executed? k = 0; for (int i 1 =0; i 1 <n 1 ; i 1 ++) k++; for (int i 2 =0; i 2 <n 2 ; i 2 ++) k++;. for (int i m =0; i m <n m ; i m ++) k++;

5 Example 2 Initial value of k is 0 There are m loops Each iteration adds 1 to k Let T i = task of traversing the ith loop; can be done n i ways, since traversal is done n i times Since no 2 tasks can be done at once, final value of k, which is the number of ways to do T i, where i = 1 … m is: n 1 + n 2 + … + n m

6 Sum rule & sets If A 1, A 2, …, A m are disjoint sets: A 1  A 2  …  A m =  Then the number of elements in the union of these sets = the sum of the number of elements in each set: |A 1  A 2  …  A m | = |A 1 | + |A 2 | + … + |A m |

7 Basic Counting Principles: Product Rule Suppose a procedure can be broken down into 2 tasks, with n 1 ways to do the first task and n 2 ways to do the second task After the first task is done, there are n 1 n 2 ways to the do the procedure Can extend product rule as sum rule was extended - in a procedure consisting of tasks T 1, T 2, … T m, each of which can be done n ways, there are n 1 *n 2 * … *n m ways to carry out the procedure

8 Example 3 (using product rule) Chairs in an auditorium are to be labeled with a letter and a number between 1 and what is the largest number of chairs that can be labeled uniquely? Two tasks: –assign one of 26 letters –assign one of 100 integers By product rule, there are 26*100 different ways a chair can be labeled - so there are 2600 unique labels

9 Example 4 (using product rule) How many bit strings of length 8 are there? There are 2 possible values for each bit So there are 2*2*2*2*2*2*2*2 or 2 8 (256) different bit strings

10 Example 5 (using product rule) How many different social security numbers are possible? –A SSN has 9 digits –Each digit has one of 10 possible values –So there are 10 9, or 1 billion possible social security numbers

11 Example 6 - counting functions How many functions are there from a set with m elements to one with n elements? –The n elements in the codomain correspond to each of m elements in the domain –So there are n*n* … * n = n m functions from a set with m elements to one with n elements

12 Example 7 - counting one-to-one functions How many one-to-one functions are there from a set with m elements to one with n elements? –If m>n there are no one-to-one functions - so let m <= n –Suppose elements in domain are a 1, a 2, … a m ; there are n ways to choose value of function at a 1 –Since the function is one to one, the number of choices for a 2 are n-1

13 Example 7 In general, the value at a k can be chosen in n-(k+1) ways By the product rule, there are: n(n-1)(n-2)*…*(n-m+1) one-to-one functions from a set of m elements to a set of n elements

14 Example 8 - assigning telephone numbers Phone numbers in North America are specified by a numbering plan: –10 digits, with 3-digit area code, 3-digit office code, and 4-digit station code –Some of these sequences are restricted to digits 1-9 or 0-1, while others may be 0-9 –If x=0..9, y=0..1 and n=2..9 the plan in place until the 1960s was nyx-nnx-xxxx the current plan is: nxx-nxx-xxxx

15 Example 8 How many unique phone numbers are possible under each plan? Old plan:n y x n n x x x x x 8*2*10*8*8*10*10*10*10*10 = 1,024,000,000 New plan:n x x n x x x x x x 8*10*10*8*10*10*10*10*10*10 = 6,400,000,000

16 Product rule & nested loops k = 0; for (int i 1 =0; i 1 <n 1 ; i 1 ++) for (int i 2 =0; i 2 <n 2 ; i 2 ++). for (int i m =0; i m <n m ; i m ++) k++; What is the value of k after the following code is executed? By the product rule, value of k is: n 1 *n 2 * … *n m

17 Product rule & sets If A 1, A 2, … A m are finite sets then the number of elements in the Cartesian product of the sets is the product of the number of elements in each set: |A 1 x A 2 x … x A m | = |A 1 | x |A 2 | x … x |A m |

18 Example 9: Combining sum rule and product rule Suppose each user on a computer system has a 6-8 character password, according to the following rules: –each character is an uppercase letter or digit –there must be at least 1 digit per password How many possible unique passwords are there?

19 Example 9 Let P = total number of passwords: –P 6 : total number with 6 characters –P 7 : total number with 7 characters –P 8 : total number with 8 characters By the sum rule, P = P 6 +P 7 +P 8

20 Example 9 To find P 6, P 7 and P 8 : –Find the number of strings of letters and digits that are n characters (including those with no digits) –Subtract from this the number of n-character strings with no digits –Result is number of n-character strings with at least one digit

21 Example 9 By the product rule, the number of strings with 6 characters is: ( ) 6 : –10 possible digits –26 possible letters –6 positions in the string The number of strings with no digits is 26 6 So the number of 6-character strings with at least one digit is: P 6 = = 1,867,866,560

22 Example 9 By the same logic, –P 7 = = 70,332,353,920 –P 8 = = 208,827,064,567 And P, which is P 6 + P 7 + P 8 = 2,684,483,063,360

23 Example 10 How many strings of 3 decimal digits do not contain the same digit 3 times? Let D=total number of 3-digit strings –product rule says D=10*10*10=1000 –Let D 0 = total number of 3-digit strings containing just 0’s - there is one of these –Similarly, D 1 =1, D 2 =1, D 3 =1, etc. By the sum rule, the number of 3-digit strings not containing the same digit 3 times is: D - (D 0 +D 1 +…+D 9 ) = = 990

24 Example 11 How many strings of 3 decimal digits end with an even digit? Using the product rule, where each “D” below represents the number of possible values for one digit of the string: D 1 * D 2 * D 3 = 10 * 10 * 5 = 500

25 Example 12 How many strings of 3 digits contain exactly 2 digits that are 4s? There are 3 ways this could occur: x44, 4x4, or 44x The value of x could be any of the other 9 digits By the product rule, the number of possible strings is 3 * 9, or 27

26 Principle of Inclusion/Exclusion If two tasks can be done at the same time, can’t simply use the sum rule to count the number of ways to do the tasks, because the ways to do both tasks at once will be counted twice To find the correct value, add the number of ways each task can be done, then subtract the number of ways to do both at once

27 Example 13 How many 8-bit strings either start with a 1 or end with 2 0s? –By the product rule, there are 2 7 (128) ways to form an 8-bit string that starts with 1 –By the same logic, there are 2 6 (64) ways to form an 8-bit string that ends with 2 0s –Finally, there are 2 5 (32) ways to form an 8-bit string that starts with 1 and ends with 2 0s –So, to form a string that starts with 1 or ends with 2 0s (but not both), there are = 160 possible ways

28 Sets and the inclusion/exclusion principle The number of elements in the union of two sets is the sum of the number of elements in both sets minus the number of elements in the intersection of the sets: |A 1  A 2 | = |A 1 | + |A 2 | - |A 1  A 2 |

29 Tree diagram Graphical representation that can be used to help solve a counting problem For example, the diagram on the next slide can be used to determine the number of bit strings with length 4 that do not have 2 consecutive 1s

30 Tree diagram We start with the two possibilities for the first digit (0 or 1) If the first digit is 1, the second must be 0 On the other hand, if the first is 0, the next could be either 0 or 1 For the third digit, there are 6 possible paths The number of possibilities for the 4th digit gives us the overall result - there are 8 different ways to form a 4-digit bit string that does not contain consecutive 1s

31 Section 4.1 Basics of Counting -ends-