CS 104 Discrete Mathematics Chapter 4 Counting 2

  • Slides: 46
Download presentation
CS 104: Discrete Mathematics Chapter 4: Counting

CS 104: Discrete Mathematics Chapter 4: Counting

2 The Basic of Counting (In Book: Chapter 6 – Section 6 -1) T.

2 The Basic of Counting (In Book: Chapter 6 – Section 6 -1) T. Mai Al-Ammar

Counting – The basic of counting 3 • Combinatorics, the study of arrangement of

Counting – The basic of counting 3 • Combinatorics, the study of arrangement of objects, is an important part of discrete mathematics. • Enumeration (Counting), the counting of objects with main properties is an important part of Combinatorics. • Counting is very important in solving many problems such that: v How many ways are there to travel from Riyadh to Makkah by car given this map? v How many license plates can be made using three letters and three digits? v How many ways are there to select 2 persons from a group of 5? v How many ways are there to arrange 5 books in a shelf? We will present the basic techniques of counting which serve as the foundation for almost all counting techniques – the product rule and the sum rule T. Mai Al-Ammar

Counting – The Product Rule 4 Suppose that a procedure can be broken down

Counting – The Product Rule 4 Suppose that a procedure can be broken down into a sequences of two tasks. If there are n 1 ways to do the first task, and for each of these ways of doing the first task there are n 2 ways to do the second task, then there are n 1* n 2 ways to do the procedure. Example 1: A new company with just two employees, Saleh and Mohammad, rents a floor of a building with 12 offices. How many ways are there to assign different offices to these two employees? The procedure of assigning offices to these two employees consists of: 1. assigning an office to Saleh which can be done in 12 ways. 2. Then assigning an office to Mohammad which can be done in 11 ways. By the product rule, there are 12 * 11 = 132 ways to assign offices to employees. T. Mai Al-Ammar

Counting – The Product Rule 5 Example 2 : The chairs of an auditorium

Counting – The Product Rule 5 Example 2 : The chairs of an auditorium are to be labeled with an uppercase English letter followed by a positive integer not exceeding 100. What is the largest number of chairs that can be labeled differently? The procedure of labeling a chair consists of two tasks: 1. Assigning to the seat one of 26 uppercase English letters. 2. Assigning to it one of the 100 possible integers. From product rule , there are 26 * 100 = 2600 ways to label chairs. Example 3: There are 32 microcomputers in a computer center. Each microcomputer has 24 ports. How many different ports to a microcomputer in the center are there? 1. Pick a microcomputer in 32 ways. 2. Pick a port in 24 ways. T. Mai Al-Ammar That is, There are 32 * 24 = 768 ports.

Counting – The Product Rule 6 Generalized Product Rule Suppose that a procedure can

Counting – The Product Rule 6 Generalized Product Rule Suppose that a procedure can be broken down into i tasks. If there are n 1 ways to do the first task and for each of these ways of doing the first task, there are n 2 ways to do the second task, so on, and there are ni ways to do the ith task, then there are n 1 * n 2 * …. * ni ways to do the procedure. Example 4: How many different bit string of length 7 are there? Each of the seven bit can be chosen in two ways ( 0 , 1) From product role, there are 27 = 128 different bit strings T. Mai Al-Ammar

Counting – The Product Rule 7 Example 5 : How many different license plates

Counting – The Product Rule 7 Example 5 : How many different license plates can be made if each plate contains a sequence of three uppercase English letters followed by three digits ? There are 26 choices for each of the three uppercase English letters, and ten choices for each of three digits, Hence by product rule there are : 26 * 10 * 10 = 17, 576, 000 possible plates. Example 6: How many functions are there from a set with m elements to a set with n elements? A function corresponds to a choice of one of the n elements in the codomain for each of the m elements in the domain. Hence by product rule there are n * n … * n= nm functions. Read Example 7, Example 8 at pages 377, 378 T. Mai Al-Ammar

Counting – The Product Rule 8 Example 9: What is the value of k

Counting – The Product Rule 8 Example 9: What is the value of k after the following code where n 1, n 2, . . , nm are positive integers has been executed? K : = 0 For i 1 : = 1 to n 1 For i 2 : = 1 to n 2. . . for im : =1 to nm k : = k + 1 • The initial value of k is zero. Each time the nested loop is traversed 1 is added to k. • Let Ti be the task of traversing the ith loop. Then the number of times the loop is traversed is the number of ways to do the tasks T 1, T 2, . . , Tm • By the product rule, it follows that the nested loop is traversed n 1* n 2 *. . * nm times k = n 1 * n 2 T. Mai Al-Ammar *. . * nm

Counting – The Product Rule 9 • The product rule is often phrased in

Counting – The Product Rule 9 • The product rule is often phrased in terms of sets as follows: If A 1, A 2, . . . , Ak are finite sets then the number of elements in the Cartesian product of these sets is |A 1×A 2× … × Ak|= |A 1|. |A 2| …. . |Ak|. • To relate this to the product rule, note that the task of choosing an element in the Cartesian product A 1×A 1 × … × Ak is done by choosing an element in A 1, an element in A 2 , and an element in Am. T. Mai Al-Ammar

Counting – The Sum Rule 10 If a task can be done either in

Counting – The Sum Rule 10 If a task can be done either in one of n 1 ways or in one of n 2 ways, where none of the set of n 1 ways is the same as any of the set on n 2 ways, then there are n 1 + n 2 ways to do the task. Example 12: Suppose that either a member of the mathematics faculty or a student who is a mathematics major is chosen as a representative to a university committee. How many different choices are there for this representative if there are 37 members of the mathematics faculty and 83 mathematics majors and no one is both a faculty member or a student? There are 37 ways to choose a member of the mathematics faculty, and there are 83 ways to choose a student who is mathematics major, by some rule it follows that there are 37 + 83 = 120 ways. T. Mai Al-Ammar

Counting – The Sum Rule 11 Generalized Sum Rule If a set of tasks

Counting – The Sum Rule 11 Generalized Sum Rule If a set of tasks can be broken into k mutually disjoint subsets of tasks A 1, A 2, . . . , Ak, the total number of tasks is |A 1| + |A 2| + · · · + |Ak|. Example 13: A student can choose a computer project by selecting a project from one of three lists which contain 23, 15, 19 projects each. Respectively, no project is on more than one list. How many possible projects are there to choose a project? By sum rule, there are 23 + 15 + 19 = 57 ways to choose a project. T. Mai Al-Ammar

Counting – The Sum Rule Example 9: 12 What is the value of k

Counting – The Sum Rule Example 9: 12 What is the value of k after the following code where n 1, n 2, . . , nm are positive integers has been executed? K : = 0 For i 1 : = 1 to n 1 k : = k + 1 For i 2 : = 1 to n 2 k : = k + 1. . For im : =1 to nm k : = k + 1 • The initial value of k is zero. This block of code is made up of m different loops. • The sum rule shows that the final value of k which is the number of ways to traverse one of the m loops is k = n 1 + n 2 +. . + nm T. Mai Al-Ammar

Counting – The Sum Rule 13 T. Mai Al-Ammar

Counting – The Sum Rule 13 T. Mai Al-Ammar

Counting – Complex Counting Problems 14 Many counting problems cannot be solved using just

Counting – Complex Counting Problems 14 Many counting problems cannot be solved using just the sum rule or just the product rule. However, many complicated counting can be solved suing both of these rules in combination. Example 16: Each user on a computer system has a password, which is six to eight characters long. Where each character is an uppercase letter or a digit. Each password must contain at least one digit. How many possible password are there? Let P is total passwords, P 6, P 7 and P 8 denote passwords of length 6, 7, and 8. By the sum rule P = P 6 + P 7 + P 8 P 6 = number of strings of uppercase letters and digits that are six characters long – number of 6 characters strings long with no digit T. Mai Al-Ammar

Counting – Complex Counting Problems 15 P 6 = 366 – 266 = 1,

Counting – Complex Counting Problems 15 P 6 = 366 – 266 = 1, 867, 866, 560 P 7 = 367 – 267 = 70, 332, 353, 920 P 8 = 368 – 268 = 2, 612, 282, 842, 880 So, P =P 6+P 7+P 8 = 2, 684, 483, 063, 360 Read Example 15, at page 381 T. Mai Al-Ammar

Counting – The Subtraction Rule ( Inclusion- Exclusion for Two Sets) 16 T. Mai

Counting – The Subtraction Rule ( Inclusion- Exclusion for Two Sets) 16 T. Mai Al-Ammar

Counting – The Subtraction Rule ( Inclusion- Exclusion for Two Sets) Example 18 :

Counting – The Subtraction Rule ( Inclusion- Exclusion for Two Sets) Example 18 : 17 How many bit strings of length 8 either start with a 1 bit or end with the two bits 00? 1 1. Construct bit strings of length 8 start with a 1 bit : 27 = 128 ways 0 2. Construct bit strings of length 8 end with the two bits 00: 0 26 = 64 ways 3. Some of ways to construct a bit string of length 8 starting with a 1 are the same as the ways to construct a bit string of length 8 that ends with two bits 00 : 1 0 0 25 = 32 ways Thus, by subtracting rule, the number of bit strings is : 128 + 64 – 32= 160 bit strings T. Mai Al-Ammar Read Example 19, at page 383

Counting – Tree Diagram 18 • Counting problems can be solved using tree diagrams.

Counting – Tree Diagram 18 • Counting problems can be solved using tree diagrams. • To use trees in counting: Ø A branch is used to represent each possible choice. Ø Leaves are used to represent the possible outcomes. Example 21 : How many bit strings of length 4 do not have consecutive 1 s? There are 8 bit strings. T. Mai Al-Ammar

Counting – Tree Diagram Example 21 : 19 A playoff between two teams with

Counting – Tree Diagram Example 21 : 19 A playoff between two teams with at most five games. The team that wins three games wins the playoff. In how many different ways can the playoff occur? There are 20 ways T. Mai Al-Ammar

20 The Pigeonhole Principle (In Book: Chapter 6 – Section 6 -2) T. Mai

20 The Pigeonhole Principle (In Book: Chapter 6 – Section 6 -2) T. Mai Al-Ammar

Counting – The Pigeonhole Principle 21 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 21 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 22 The pigeonhole principle is also called the Dirichlet

Counting – The Pigeonhole Principle 22 The pigeonhole principle is also called the Dirichlet drawer principle, because the German mathematician Dirichlet often used this principle in his work. • Corollary 1: A function f from a set with k+1 or more elements to a set with k elements is not one- to- one. • Proof : Suppose that for each element in codomain of f we have a box that contains elements of elements in the domain. The domain contain k+1 elements and codomain have just k boxes By pigeonhole principle, one of boxes in codomain must have at least two elements. That means, f cannot be one-to-one T. Mai Al-Ammar

Counting – The Pigeonhole Principle 23 Example 1: Among any group of 367 people,

Counting – The Pigeonhole Principle 23 Example 1: Among any group of 367 people, there must be at least two with the same birthday, because there are only 366 possible birthdays. Example 2: In any group of 27 English words, there must be at least two that begin with the same letter, because there are only 26 letters in English alphabet. Example 3: How many students must be in a class to guarantee that at least two students receive the same score on the final exam, if the exam is graded on a scale from 0 to 100 marks? There are 101 possible scores on the final. The pigeonhole principle shows that among any 102 students there must be at least two students with the same score. T. Mai Al-Ammar

Counting – The Pigeonhole Principle 24 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 24 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 25 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 25 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 26 T. Mai Al-Ammar

Counting – The Pigeonhole Principle 26 T. Mai Al-Ammar

27 Permutations and Combinations (In Book: Chapter 6 – Section 6 -3) T. Mai

27 Permutations and Combinations (In Book: Chapter 6 – Section 6 -3) T. Mai Al-Ammar

Counting – Permutations and Combinations 28 There are two important ways to solve many

Counting – Permutations and Combinations 28 There are two important ways to solve many counting problems : 1. Finding the number of ways to arrange a specified number of distinct elements of a set of particular size. Permutations 2. Finding the number of ways to select a particular number of elements from a set of particular size. Combinations T. Mai Al-Ammar

Counting – Permutations 29 T. Mai Al-Ammar

Counting – Permutations 29 T. Mai Al-Ammar

Counting – Permutations Example 1: 30 In how many ways can we select three

Counting – Permutations Example 1: 30 In how many ways can we select three students from a group of five students to stand in line for a picture ? In how many ways we arrange all five of these students in a line for a picture? To arrange three students: There are five ways to select first student, and there are four ways to select second student, and three ways to select third student: 5 * 4 * 3 = 60 ways To arrange five students: 5 * 4 * 3 * 2 * 1 = 120 ways. Example 3: Let S = {a, b, c}. The 2 -permutations of S are the ordered arrngements : a, b; a, c; b, a; b, c; c, a; c, b , There are 6 2 -permutaions of the set with 3 elements , P(3, 2) = 3 * 2 = 6 T. Mai Al-Ammar

Counting – Permutations Example 4: 31 How many ways are there to select a

Counting – Permutations Example 4: 31 How many ways are there to select a first-prize winner, a second prize winner, and a third-prize winner from 100 different people who have entered a contest? It is a number of 3 -permutations of a set of 100 elements. P(100, 3) = 100 * 99 * 98 = 970, 200 Example 5: Suppose that there are 8 runners in a race. The winner receives a gold medal, the second receives a silver medal, and the third receives a bronze medal. How many different ways are there to award these medals, if all possible outcomes of the race can occur and there are no ties? It is the number of 3 -permutations of a set with 8 elements. Hence, there are P(8, 3) = 8 * 7 * 6 = 336 possible ways. T. Mai Al-Ammar

Counting – Permutations 32 Example 6 : Suppose that a saleswoman has to visit

Counting – Permutations 32 Example 6 : Suppose that a saleswoman has to visit eight different cities. She must begin her trip in a specified city, but she can visit the other seven cities in any order she wishes. How many possible orders can the saleswoman use when visiting these cities? The number of possible paths between the cities is the number of permutations of seven elements, because the first city is determined. Consequently, there are 7! = 7 * 6 * 5 * 4 * 3 *2 * 1 = 5040 ways Example 7 : How many permutations of the letters ABCDEFGH contain the string ABC? Because the letters ABC must occur as a block, we can find the answer by finding the number of permutations of 6 objects: 6! = 720 T. Mai Al-Ammar

Counting – Combinations 33 T. Mai Al-Ammar

Counting – Combinations 33 T. Mai Al-Ammar

Counting – Combinations 34 T. Mai Al-Ammar

Counting – Combinations 34 T. Mai Al-Ammar

Counting – Combinations 35 T. Mai Al-Ammar

Counting – Combinations 35 T. Mai Al-Ammar

Counting – Combinations 36 T. Mai Al-Ammar

Counting – Combinations 36 T. Mai Al-Ammar

37 Binomial Coefficients and Identities (In Book: Chapter 6 – Section 6 -4) T.

37 Binomial Coefficients and Identities (In Book: Chapter 6 – Section 6 -4) T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 38 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 38 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 39 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 39 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 40 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 40 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 41 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 41 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 42 T. Mai Al-Ammar

Counting - Binomial Coefficients and Identities 42 T. Mai Al-Ammar

Counting – Pascal’s Identity and Triangle 43 T. Mai Al-Ammar

Counting – Pascal’s Identity and Triangle 43 T. Mai Al-Ammar

Counting – Pascal’s Identity and Triangle 44 T. Mai Al-Ammar

Counting – Pascal’s Identity and Triangle 44 T. Mai Al-Ammar

Counting – Vandermonde’s Identity 45 T. Mai Al-Ammar

Counting – Vandermonde’s Identity 45 T. Mai Al-Ammar

46 End Chapter 4 T. Mai Al-Ammar

46 End Chapter 4 T. Mai Al-Ammar