Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 from the set S to the set {1, 2, 3, …, n}. This shows that there are n distinct elements in the set S. While this is a feasible approach for sets with small cardinality, we do not wish to enumerate all of the elements in a set with large cardinality. We will now introduce techniques that will allow us to count the number of objects in a set without having to enumerate all of the objects.

2 The Product Rule: Suppose that a procedure can be broken down into a sequence of two tasks that must be done in succession in order to complete the procedure. If there are n 1 ways to do the first task and n 2 ways to do the second task after the first task has been completed, then there are n 1 * n 2 ways to complete the procedure. Ex: The chairs of an auditorium are to be labeled with a capital letter and a positive integer not exceeding 100. What is the largest number of chairs that can be labeled differently under this scheme? Examples of labels using this scheme are A29, D100, C1, etc. We can think of the procedure of choosing a label for a chair as two successive tasks: We first choose a letter, then we choose a positive integer not exceeding 100. Determining how many chairs can be labeled differently under this scheme is equivalent to determining how many different ways there are of completing this procedure. By the product rule, there are 26 * 100 = 2600 different labels. Note that to choose a label we must complete both tasks [product rule].

3 The Generalized Product Rule: If a procedure can be broken down into a sequence of m tasks that must be done in succession in order to complete the procedure and if there are n 1 ways to do the first task and n 2 ways to do the second task after the first has been completed, and n 3 ways to do the third task after the first two have been completed, …, then there are n 1 * n 2 * … * n m ways to complete the procedure. Ex: How many different bit strings are there of length 9? We already know that the answer is 2 9. However, we can verify this by applying the product rule. Consider that to choose a bit string of length 9, we must choose the first bit, then choose the second bit, …, and finally choose the ninth bit. There are nine tasks to perform in succession and each of them can be done in 2 ways (choose a 0 or a 1). So by the product rule, there are 2*2*2*2*2*2*2*2*2 = 2 9 ways to choose a bit string of length 9.

4 Ex: How many different license plates can be made if each plate must have 3 capital letters followed by 4 digits? Ex: How many different functions are there from a set with m elements to a set with n elements. Recall that the requirement for a map to be a function is that each of the m elements in the domain is mapped to exactly one of the n elements of the range. Hence we have m tasks to perform (choosing an element of the range to map to for each of the m elements) and n ways to perform each task (n choices for where to map each element to). So by the product rule, there are n*n*…*n = n m ways to construct a function from a set with m elements to a set with n elements. We have 7 task to complete in succession and the product rule tells us that there are 26*26*26*10*10*10*10 = 26 3 *10 4 different plates. Note that in this problem each plate is required to have exactly 7 chars.

5 Ex: How many different one-to-one functions are there from a set with m elements to a set with n elements. Before we proceed to try to count the functions, recall that if m > n then there are no one-to-one functions, so the answer is 0 in this case. If m  n then we have m tasks to perform in succession in order to construct a one-to-one function. For the ‘first’ element in the domain, we have n elements of the codomain to which we can map. For the ‘second’ element in the domain, we have n – 1 elements of the codomain to which we can map, …, for the ‘mth’ element in the domain, we have n – (m – 1) elements of the codomain to which we can map. So the product rule tells us that there are n*(n – 1) * … * (n – (m – 1)) = n!/(n – m)! ways to construct a one-to-one function from a set with m elements to a set with n elements if m  n (and 0 ways if m > n).

6 The Sum Rule: Suppose that a procedure can be completed by either performing one task or another task. If there are n 1 ways to do one of the tasks and n 2 ways to do the other task and if these tasks can not be done at the same time, then there are n 1 + n 2 ways to complete the procedure. Ex: Suppose that we need to appoint a member of a committee and this member must be either a mathematics professor or a computer science professor. If there are 28 mathematics professors and 36 computer science professors (and there are no joint appointments) then how many choices do we have for the committee member? We can complete the procedure of appointing a committee member by either choosing a mathematics professor or choosing a computer science professor. And since there are no joint appointments, then the sum rule tells us that there are = 64 different ways to select the committee member.

7 The Generalized Sum Rule: If a procedure can be completed by performing one of m tasks and if there are n 1 ways to do the first task and n 2 ways to do the second task, …, and n m ways to do the mth task and no two of the tasks can be done at the same time, then there are n 1 + n 2 + … + n m ways to complete the procedure. Ex: A college requirement can be filled by taking a course in History, Economics, Sociology, or Psychology. If there are 20 History courses, 23 Economics courses, 17 Sociology courses, and 31 Psychology courses (none of which are cross-listed) offered this semester, how many different ways are there to fulfill the requirement this semester? The generalized sum rule tells us that there are = 91 ways to fulfill the requirement this semester. Sometimes we will need to use the product rule and sum rule in tandem to solve a counting problem.

8 Ex: A password is required to have 6 to 8 characters, each of which is an uppercase letter, lowercase letter, or a digit. How many valid passwords are there? The procedure of choosing a valid password can be completed by performing one of 3 tasks, P 6, P 7, or P 8, where P i is the task of choosing a password of length i. Clearly no two of these tasks can be performed at the same time, so the sum rule tells us that the procedure of choosing a password can be done in P 6 + P 7 + P 8 ways. Similarly, when we choose each character in a password, the sum rule tells us that there are = 62 ways to choose each character. Then by the product rule, there are 62 6 ways to complete P 6, 62 7 ways to complete P 7, and 62 8 ways to complete P 8. So there are ways to choose a valid password under the given constraints. That is, there are 221,918,520,426,688 different valid passwords.

9 Ex: What if we require our passwords to have at least 1 digit in them? We just found that the total number of passwords that satisfy our original criteria was 221,918,520,426,688. If we now require that for a password to be valid it must contain at least 1 digit, then some of the passwords in the above count are not valid (namely those with no digits in them). So if we count the number of the above passwords that have no digits, then we can subtract this from the total above to leave us with a count of the number of passwords that satisfy our original criteria and contain at least 1 digit. Once again the sum rule tells us that there are N 6 + N 7 + N 8 ways to choose a password with no digits if N i is the number of ways to choose a password of length i with no digits. Then the sum rule tells us there are = 52 ways to choose each character in one of these passwords. So by the product rule there are ways to choose a password with no digits. Subtracting, there are 167,410,949,583,040 valid passwords left.

10 The Principle of Inclusion-Exclusion One of the requirements for the sum rule is that the tasks to be done can’t be done at the same time. When two tasks can be done at the same time, if we simply add the number of ways to do each task then we over count the number of ways to complete the procedure because some ways are counted in more than one task. To correct for this over counting, we introduce the principle of inclusion-exclusion. Ex: If we must appoint a committee representative with the requirement that the representative is a math major or a CS major, how many ways are there to appoint this representative? If we try to apply the sum rule and simply add the number of math majors and the number of CS majors, then we will only get the correct answer if there are no students majoring in both math and CS. To correct for this, we must simply subtract out the number of students majoring in both math and CS.

11 The Principle of Inclusion-Exclusion: Suppose that a procedure can be completed by either performing one task or another task. If there are n 1 ways to do one of the tasks and n 2 ways to do the other task and if there are m ways to do both tasks at the same time, then there are n 1 + n 2 – m ways to complete the procedure. Ex: How many bit strings of length 8 either start with a 1 bit or end with two 0 bits? We can complete the procedure of selecting an appropriate bit string by either choosing a bit string of length 8 that starts with a 1 bit or choosing a bit string of length 8 that ends with two 0 bits. However, it is possible to do both tasks at once, so we must subtract out the number of ways to choose a bit string of length 8 that starts with a 1 bit and ends with two 0 bits. There are 2 7 bit strings of length 8 that start with a 1 bit (choose the last 7 bits), 2 6 bit strings of length 8 that end with two 0 bits (choose the first 6 bits), and 2 5 bit strings of length 8 that start with a 1 bit and end with two 0 bits. So there are – 2 5 = 160 desired bit strings.


Download ppt "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."

Similar presentations


Ads by Google