460 likes | 516 Views
Agenda. Lecture Content: Counting Methods Permutation and Combination Pigeonhole Principle Review & Exercise. Counting Methods. Counting Problem: Example.
E N D
Agenda • Lecture Content: • Counting Methods • Permutation and Combination • Pigeonhole Principle • Review & Exercise
Counting Problem: Example Passworddalamsuatusistemkomputerterdiridari 6, 7, atau 8 karakter. Setiapkarakteradalah digit bilangandesimalatauhurufdalamalfabet. Setiappaswordharusmemuat paling sedikitsatu digit bilangandesimal. Ada berapabanyakpassword yang berbeda?” “Berapabanyakcara yang mungkindilakukandalammemilih 11 pemaindalamsuatutimsepak bola yang memiliki 20 pemain?” Selainitu, counting adalahdasardalammenghitungpeluangdarikejadian-kejadiandiskrit. (“Berapakahpeluanguntukdapatmemenangkansuatulotere?”) Berapa kalisuatu loop pada program dijalankan estimasi run time darisuatualgoritma
The Basics of Counting • The Multiplication Principle • The Addition Principle • The Inclusion – Exclusion Principle
The Multiplication Principle If an activity can be constructed in t successive steps and step 1 can be done in n1 ways, step 2 can then be done in n2 ways, …, and step t can then be done in nt ways, then the number of different possible activities is n1 * n2 * … * nt.
Example 1 A new company with just two employees, A and B, rents a floor of a building with 12 offices. How many ways are there to assign different offices to these two employees? Assigning an office to A: 12 ways Assigning an office to B: 11 ways Assigning offices to A and B: 12 x 11 = 132 ways
Example 2 The chairs of an auditorium are to be labeled with a letter and a positive integer not exceeding 100. What is the largest number of chairs that can be labeled differently? Assigning a letter to a chair: 26 ways Assigning a positive integer to a chair: 100 ways Assigning a letter and a positive integer to a chair: 26 x 100 = 2600 ways
Example 3 How many different bit strings of length seven are there? Each of the seven bits can be chosen in two ways, because each bit is either 0 or 1. Total: 2 x 2 x 2 x 2 x 2 x 2 x 2 = 27 = 128 different bit strings
Example 4 How many different license plates are available if each plate contains a sequence of three letters followed by three digits? 26 choices for each of the three letters and 10 choices for each of the three digits. Total: 26 . 26 . 26 . 10 . 10 . 10 = 17,576,000 possible license plates
The Addition Principle Suppose that X1, …, Xtare sets and that the i-th set Xi has nielements. If {Xi, …, Xt} is a pairwise disjoint family (ie. If i ≠ j, Xi Xj = ), the number of possible elements that can be selected from X1 or X2 or … or Xt is n1 + n2 + … + nt
The Addition Principle 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 of n2 ways, then there are n1 + n2ways to do the task.
Example 1 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 math faculty and 83 math major and no one is both a faculty member and a student? 37 + 83 ways to pick a representative
Example 2 A student can choose a computer project from one of three lists. The three lists contain 23, 15, and 19 possible projects. No project is on more than one list. How many possible projects are there to choose from? 23 + 15 + 19 = 57 ways to choose a project
Example 3 (Combination Multiplication and Addition) In how many ways can we select two books from different subjects among five distinct computer science books, three distinct mathematics books and two distinct art books. Multiplication: 1 comp science and 1 math = 5 * 3 = 15 1 math and 1 art = 3 * 2 = 6 1 comp science and 1 art = 5 * 2 = 10 Addition: 15 + 6 + 10 = 31 ways to select two books
The Inclusion – Exclusion Principle Suppose that a task can be done in n1 or in n2ways, but that some of the set of n1 ways to do the task are the same as some of the n2 other ways to do the task. To correctly count the number of ways to do the two tasks, add the number of ways to do it in one way and the number of ways to do it in the other way, and then subtract the number of ways to do the task in a way that is both among the set of n1 ways and the set of n2 ways.
The Inclusion – Exclusion Principle |X Y| = |X| + |Y| - |X Y|
Example 1 How many bit strings of length eight either start with a 1 bit or end with the two bits 00? 1 _ _ _ _ _ _ _ = 27 = 128 ways _ _ _ _ _ _ 00 = 26 = 64 ways 1 _ _ _ _ _ 00 = 25 = 32 ways Total: |A B| = |A| + |B| -|A B| 128 + 64 – 32 = 160 ways
Example 2 The number of students having computer science as a major is 13. The number of students having mathematics as a major is 21. The number of students majoring in both computer science and mathematics is 10 |A B| = |A| + |B| - |A B| = 13 + 21 – 10 = 24
Example 3 There are 1807 freshmen at your university. 453 are taking a course in computer science, 567 are taking a course in mathematics, and 299 are taking courses in both. How many are not taking a course either computer science or in mathematics? |A B| = |A| + |B| - |A B| = 453 + 567 – 299 = 721 not taking a course either computer science or in mathematics : 1807 – 721 = 1086
Summary If we counting objects that are constructed in successive steps, we use the Multiplication Principle. If we have disjoint sets of objects and we want to know the total number of objects, we use the Addition Principle.
Introduction • Finding the number of ways to arrange / to select a specified number of distinct elements of a set of a particular size, where: • The order of these elements matters. • In how many ways can we select three students in ordered from a group of five students to stand in line for a picture • The order of elements selected does not matter. • How many different committees of three students can be performed from a group of four students
Permutations: Illustrations • In how many ways can we select three students from a group of five students to stand in line for a picture? 5 * 4 * 3 = 60 ways • In how many ways can we arrange all five of these students in a line for a picture? 5 * 4 * 3 * 2 * 1 = 120 ways
Permutations • A permutation of a set of distinct objects is an ordered arrangement of these objects. An ordered arrangement of r elements of a set is called an r-permutation. • Notation: P(n, r) • n : number of elements • r : number of ordered elements
Example • S = {a, b, c} • The 2-permutations of S: a, b; a, c; b, a; b, c; c, a; c, b • P(3, 2) = 3 * 2 = 6
Permutations P(n, r) = n * (n-1) * (n-2) * … * (n – r + 1) P(n, r) = n! / (n – r)! • n : number of elements • r : number of ordered elements • 0 r n
Example 1 • 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? • P(100, 3) = 100 * 99 * 98 = 970,200
Example 2 • There are 8 numbers in a race. The winner receives a gold medal, the second-place finisher receives a silver medal, and the third-place finisher receives a bronze medal. How many different ways are there to award these medals? P(8, 3) = 8 * 7 * 6 = 336
Example 3 • A saleswomen 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. How many possible orders can she use when visiting these cities? P(7, 7) = 7! = 7 * 6 * 5 * 4 * 3 * 2 * 1 = 5040 • Because the first city is determined, so only the remaining seven can be ordered arbitrarily.
Example 4 • How many permutations of the letters ABCDEFGH contain the string ABC? P(6, 6) = 6! = 720 • Because the letters ABC must occur as a block, the elements are ABC, D, E, F, G, H.
Combinations: Illustration • How many different committees of three students can be performed from a group of four students {a, b, c, d}? • {a, b, c}, {a, b, d}, {a, c ,d}, {b, c, d}
Combinations • Anr-combinationof elements of a set is an unordered selection of r elements from the set. Thus, an r-combination is simply a subset of the set with r elements. • Notation: C(n, r) • n : number of elements • r : number of unordered elements
Example • How many different committees of two students can be performed from a group of four students {a, b, c, d}? • {a, b}, {a, c}, {a, d}, {b, c}, {b, d}, {c, d}
Combinations C(n, r) = n! / (r! (n – r)!) • n : number of elements • r : number of unordered elements • 0 r n
Example 1 • How many poker hands of five cards can be dealt from a standard deck of 52 cards? C(52, 5) = 52! / (5! (52 – 5)!) = 52! / (5! * 47!) = 52 * 51 * 50 * 49 * 48 / 5! = 2, 598,960
Example 2 • How many ways are there to select 47 cards from a standard deck of 52 cards? C(52, 47) = 52! / (47! (52 – 47)!) = 52! / (47! * 5!) = 52 * 51 * 50 * 49 * 48 / 5! = 2, 598,960 = C(52, 5)
Combinations C(n, r) = C(n, n - r) = n! / ((n-r)! (n – (n – r))!) = n! / ((n-r)! r!)
Example 1 • How many ways are there to select five players from a 10-members tennis team to make a trip to a match at another school? C(10, 5) = 10! / (5! * 5!) = 252
Example 2 • A group of 30 people have been trained as astronauts to go on the first mission to Mars. How many ways are there to select a crew of six people to go on this mission? C(30, 6) = 30! / (6! * 24!) = 593,775 ways
The Pigeonhole Principle • Suppose that a flock of 20 pigeons flies into a set of 19 pigeonholes to roost. • Because there are 20 pigeons but only 19 pigeonholes, at least one of these 19 pigeonholes must have at least two pigeons in it.
The Pigeonhole Principle • If n pigeons fly into k pigeonhole and k<n≤2k, some pigeonhole contains at least two pigeons. • 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. • Decide which objects will play the roles of the pigeons and which objects will play the roles of the pigeonholes.
Example • Among any group of 366 people, there must be at least two with the same birthday. • Because one year is 365 days, there are only 365 possible birthdays. • In any group of 27 Indonesian words, there must be at least two that begin with the same letter. • Because there are only 26 letters in the Indonesian alphabet.
Example • 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 points? • There 101 possible scores on the final. The pigeonhole principle shows that among any 102 students there must be at least 2 students with the same score.
The Generalized Pigeonhole Principle • If N objects are placed into k boxes, then there is at least one box containing at least N/kobjects. • Example: • Among 100 people, how many people were born in the same month? • there are at least 100/12 = 9
Example • Possible grades: A, B, C, D, F • What is the minimum number of students required in a class to be sure that at least six will receive the same grade? • Find the smallest integer N, such that N/5 = 6. • N = 5 * 5 + 1 = 26