1 / 46

CS 104: Discrete Mathematics

CS 104: Discrete Mathematics. Chapter 4: Counting. The Basic of Counting ( In Book: Chapter 6 – Section 6-1 ). Counting – The basic of counting. Combinatorics , the study of arrangement of objects, is an important part of discrete mathematics.

kprentice
Download Presentation

CS 104: Discrete Mathematics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 104: Discrete Mathematics Chapter 4: Counting

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

  3. Counting – The basic of counting • 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: • How many ways are there to travel from Riyadh to Makkah by car given this map? • How many license plates can be made using three letters and three digits? • How many ways are there to select 2 persons from a group of 5? • 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

  4. Counting – The Product Rule Suppose that a procedure can be broken down into a sequences of two tasks. If there are n1 ways to do the first task, and for each of these ways of doing the first task there are n2 ways to do the second task, then there are n1* n2 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: assigning an office to Saleh which can be done in 12 ways. 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

  5. Counting – The Product Rule 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: Assigning to the seat one of 26 uppercase English letters. 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. That is, There are 32 * 24 = 768 ports. T. Mai Al-Ammar

  6. Counting – The Product Rule Generalized Product Rule Suppose that a procedure can be broken down into i tasks. If there are n1 ways to do the first task and for each of these ways of doing the first task, there are n2 ways to do the second task, so on, and there are ni ways to do the ithtask, then there are n1 * n2 * …. * 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

  7. Counting – The Product Rule 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 * 26 * 26 * 10 * 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

  8. Counting – The Product Rule • Example 9: • What is the value of k after the following code where n1, n2, .. , nm are positive integers has been executed? • 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 T1, T2, .. , Tm • By the product rule, it follows that the nested loop is traversed n1* n2 * .. * nm times  k = n1* n2 * .. * nm K := 0 For i1 := 1 to n1 For i2 := 1 to n2 . . . for im :=1 to nm k := k + 1 T. Mai Al-Ammar

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

  10. Counting – The Sum Rule If a task can be done either in one of n1 ways or in one of n2 ways, where none of the set of n1 ways is the same as any of the set on n2 ways, then there are n1 + n2 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

  11. Counting – The Sum Rule Generalized Sum Rule If a set of tasks can be broken into k mutually disjoint subsets of tasks A1, A2, . . ., Ak, the total number of tasks is |A1| + |A2| + · · · + |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

  12. Counting – The Sum Rule • Example 9: • What is the value of k after the following code where n1, n2, .. , nm are positive integers has been executed? • 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 = n1 + n2 + .. + nm K := 0 For i1 := 1 to n1 k := k + 1 For i2 := 1 to n2 k := k + 1 . . For im :=1 to nm k := k + 1 T. Mai Al-Ammar

  13. Counting – The Sum Rule • The sum rule is often phrased in terms of sets as follows: If A1, A2, . . ., Am are pairwise disjoint finite sets then the number of elements in the union of these sets is • |A1 A2… ×Am|= |A1| + |A2| …..+ |Am| • To relate this to the sum rule, note that there are |Ai| ways to choose an element from Ai for A1, A2, .. Am . T. Mai Al-Ammar

  14. Counting – Complex Counting Problems 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, P6, P7 and P8 denote passwords of length 6, 7, and 8. By the sum rule P = P6 + P7 + P8 P6 = 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

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

  16. Counting – The Subtraction Rule ( Inclusion- Exclusion for Two Sets) • If a task can be done in either n1 ways or n2 ways then the number of ways to do the task is n1+n2 minus the number of ways to do the task that are common to the two different ways. • The subtraction rule is known as the principle of inclusion – exclusion especially when it is used to count the number of elements in the union of two sets which is : T. Mai Al-Ammar

  17. Counting – The Subtraction Rule ( Inclusion- Exclusion for Two Sets) Example 18 : How many bit strings of length 8 either start with a 1 bit or end with the two bits 00? Construct bit strings of length 8 start with a 1 bit : 2. Construct bit strings of length 8 end with the two bits 00: 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 : Thus, by subtracting rule, the number of bit strings is : 128 + 64 – 32= 160 bit strings Read Example 19, at page383 0 1 1 0 27 = 128 ways 26 = 64 ways 25 = 32 ways 0 0 T. Mai Al-Ammar

  18. Counting – Tree Diagram • 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 1s? • There are 8 bit strings. T. Mai Al-Ammar

  19. Counting – Tree Diagram Example 21 : 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 Al-Ammar

  21. Counting – The Pigeonhole Principle • Suppose that 20 pigeons flies into a set of 19 pigeonhole. Because there are 20 pigeons but only 19 pigeonhole (19 <20) at least one of these pigeonhole must have at least two pigeons in it. That is, If n pigeons fly into k pigeonholes and k < n, then some pigeonhole contains at least two pigeons. • Theorem (The Pigeonhole Principle): • If k is a positive integer and k+1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects. • Proof : • prove the theorem by contrposition : • : none of k boxes contains more than one object. • Then the total number of objects would be at most k, which is • since p is there is k+1 objects • thus, the original statement is true T. Mai Al-Ammar

  22. Counting – The Pigeonhole Principle • The pigeonhole principle is also called the Dirichlet drawer principle, because the German mathematician Dirichletoften 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 notone- 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

  23. Counting – The Pigeonhole Principle 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

  24. Counting – The Pigeonhole Principle Theorem (The Generalized Pigeonhole Principle): If N objects are placed into k boxes, then there is at least one box containing at least ⌈N/k⌉objects. Proof: prove the theorem by contrposition : : Suppose that none of boxes contains more than ⌈N/k⌉-1 objects. then the total number of objects is at most: k(⌈⌉-1) < k((+1) – 1) = N. where the inequality ⌈N/k⌉ < (N/k)+1 has been used. Thus, number of objects < N This is a contradiction, because there a total of N objects: thus, the original statement is true ceiling(x) = is the smallest integer not less than x T. Mai Al-Ammar

  25. Counting – The Pigeonhole Principle Example 5 : Among 100 people, there are at least ⌈100/12⌉= 9 who were born in the same month. Example 6: What is the minimum number of students required in CS104 class to be sure that at least six will receive the same grade, if there five possible grades A, B, C, D and F? The minimum number of students needed to ensure that at least 6 students receive the same grade is the smallest integer N such that: = 6  If you have only 25 , no 6 students have received same grade , so N = 26 = a a-1 < n T. Mai Al-Ammar

  26. Counting – The Pigeonhole Principle Exercise 2 : Show that if there are 30 students in a class, then at least two have last names that begin with the same letters. Let N = number of students Let k = 26 English letters From the pigeonhole principle, at least one box ( letter) contains objects (students) , i.e. there is students have the same letter in the last name. T. Mai Al-Ammar

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

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

  29. Counting – Permutations • Definition: • A permutation of a set of distinct objects is an ordered arrangement of these objects. • We are also interested in ordered arrangements of some of the elements of a set. An ordered arrangement of r elements of a set in called an r-permutation. • The number of r-permutations of a set with n elements is denoted by P(n , r ) which could be calculated using the product rule. • 1 • P(n , 0 ) = 1 “ there is exactly one way to arrange zero element” , there is one list with no elements “ empty list”. T. Mai Al-Ammar

  30. Counting – Permutations Example 1: 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

  31. Counting – Permutations Example 4: 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

  32. Counting – Permutations 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

  33. Counting – Combinations • Definition: • An r-combination of elements of a set is an unordered selection of r elements from the set, i.e. it is simply a set of size r. • The number of r-combinations of a set with n distinct elements is denoted by C(n, r) or . T. Mai Al-Ammar

  34. Counting – Combinations Example 8: How many different committees of three students can be formed from a group of four students? We need find the number of subsets with three elements from the set containing 4 students: C(4 ,3) = = 4 ways Example : A basketball squad consists of 12 players, 5 of which make up a team. How many different teams of players can you make from the 12? Total number of ways is C(12, 5) = = 792 ways T. Mai Al-Ammar

  35. Counting – Combinations Example : Suppose you have to select 11 students for a football team. There are 6 students in group-1, 8 students in group-2, and 3 students in group-3 to choose from. How many different football team can you make? Total number of ways is C(17,11) = = 12376 ways Example: Suppose you have to select 11 students for a football team. There are 6 students in group-1, 8 students in group-2, and 3 students in group-3 to choose from. Now suppose you want to select 4 from group-1, 5 from group-2, and 2 from group-3 in that team. How many different football team can you make? Total number of ways is C(6,4) x C(8,5) x C(3,2) = = 15 * 56 * 3 = 2520 ways. T. Mai Al-Ammar

  36. Counting – Combinations Example 15 : Suppose that there are 9 faculty members in the mathematics department and 11 in the computer science department. How many ways are there to select a committee to develop a discrete mathematics course at a school if the committee is to consist of three faculty members from the mathematics department and four from the computer science department? C(9, 3) * C ( 11, 4) = Read Example 11, Example 12, Example 13 at pages 399, 401 T. Mai Al-Ammar

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

  38. Counting - Binomial Coefficients and Identities • A binomial expression is the sum of two terms such as x + y • The binomial theorem gives the coefficients of the expansion of powers of binomial expression. • The binomial Theorem: • Let x and y be variables and let n be a nonnegative integer, then: • is a binomial coefficient T. Mai Al-Ammar

  39. Counting - Binomial Coefficients and Identities Example 1: What is the expansion of ? + + + = + 6 + 4 + Example 2 : What is the coefficient of in the expansion of (x +y)25 ? From the binomial theorem it follows that this coefficient : = T. Mai Al-Ammar

  40. Counting - Binomial Coefficients and Identities Example 3 : What is the coefficient of in the expansion of (2x - 3y)25 ? First note that this expression equals : (2x + (- 3y))25 From the binomial theorem it follows that this coefficient : (2x + (- 3y))25 = = - T. Mai Al-Ammar

  41. Counting - Binomial Coefficients and Identities • Corollary 1 : • Let n be a nonnegative integer, then : • Proof: • First method: • = • Second method: • A set with n elements has a total of different subsets. • Each subset has zero elements, one elements, two elements. … , n elements • There are subsets with zero elements, subsets with one elements, … , subsets with n elements, = • That is : T. Mai Al-Ammar

  42. Counting - Binomial Coefficients and Identities Corollary 2: Let n be a positive integer, then : Proof: When we use the binomial theorem with x = -1 and y =1 , then = Corollary 3 : Let n be a nonnegative integer, then : Proof: = = T. Mai Al-Ammar

  43. Counting – Pascal’s Identity and Triangle • Pascal’s Identity : • Let n and k be positive integers with n k , then • + • This triangle is known as Pascal’s Triangle. • Pascal’s identity shows that when two adjacent binomial coefficients in this triangle are added, the binomial coefficient in the next row between these two coefficients is produced. • The nth row in the triangle consists of the Binomial coefficients C(n, j), 0≤j ≤ n. T. Mai Al-Ammar

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

  45. Counting – Vandermonde’s Identity • Vandermonde’s Identity : • Let m , n , and r be nonnegative integers with r not exceeding either m or n ,then: • Corollary 4 : • If n is a nonnegative integer, then 2 • Proof: • We use Vandermonde’s identity with m = n = r to obtain : • = 2 note that T. Mai Al-Ammar

  46. End Chapter 4 T. Mai Al-Ammar

More Related