1 / 53

# Computing Fundamentals 2 Lecture 5 Combinatorial Analysis

Computing Fundamentals 2 Lecture 5 Combinatorial Analysis. Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K408 Based on Chapter 16. A Logical approach to Discrete Math By David Gries and Fred B. Schneider. Combinatorial Analysis. Counting Permutations Combinations

Télécharger la présentation

## Computing Fundamentals 2 Lecture 5 Combinatorial Analysis

E N D

### Presentation Transcript

1. Computing Fundamentals 2Lecture 5Combinatorial Analysis Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K408 Based on Chapter 16. A Logical approach to Discrete Math By David Gries and Fred B. Schneider

2. Combinatorial Analysis • Counting • Permutations • Combinations • The Pigeonhole Principle • Examples

3. Permutation Combination • Fruit salad is a combination of apples, grapes and bananas We don't care what order the fruits are in. • The permutation that will open the lock is 942, we do care about the order.

4. Combinatorial Analysis • Combinatorial analysis deals with permutations of a set or bag and combinations of a set, which lead to binomial coefficients and the Binomial Theorem. • Cardinality of set is denoted as |A| • Example if A = {1,3,6} then |A|=3

5. Rules of Counting • Rule of sums (addition): The size of the union on n finite pair wise disjoint sets is the sum of their sizes. • Rule of product (multiplication): The size of the cross product of n sets is the product of their sizes . • Rule of difference: The size of a set with a subset removed is the size of the set minus the size of the subset.

6. Rules of Counting • Difference Rule • If B ⊆ A or A ⋂ B then |A - B| is |A| - |B| B A As a logical statement

7. Rules of Counting • Inclusion–exclusion principle

8. Rules of Counting • Inclusion–exclusion principle

9. Product Rule Example • If each license plate contains 3 letters and 2 digits. How many unique licenses could there be? • Using the rule of products. • 26  26  26  10  10 = 1,757,600

10. Multiplication Principle for Counting • In general, if n operations 01, 02…0n are performed in order, with possible number of outcomes N1, N2 … Nn, respectively, then there are N1 • N2 • …Nn possible combined outcomes of the operations performed in the given order.

11. Addition Principle or Counting • For any two sets of A and B, |A ∪ B|= |A|+ |B|– |A ∩ B| If A and B are disjointed then, |A ∪ B|= |A|+ |B|

12. Permutation of a set • A permutation of a set of elements is a linear ordering (or sequence) of the elements e.g. • Given set S = {1,4,5} • Permutation A : 1, 4, 5 • Permutation B : 1, 5, 4 • An anagram is a permutation of words. • There are n  (n – 1)  (n - 2) .. 1 permutations of a set of n elements. • This is called factorial n, written n!

13. Calculating Factorial module FACT { protecting(INT) -- Two notations for factorial op _! : Nat -> NzNat {prec 10} op fact : Nat -> NzNat var N : Nat -- Notation 1 eq 0 ! = 1 . ceq N ! = N * (N - 1) ! if N > 0 . -- Notation 2 eq fact(0) = 1 . ceq fact(N) = N * fact(N - 1) if N > 0 . } open FACT red 4 ! . red fact(4) .

14. Permutation of a set • Sometimes we want a permutation of size r from a set of size n. • (16.4) P(n,r) = n!/(n-r)! • The number of 2 permutations of BYTE is • P(4,2) = 4!/(4-2)! = 4  3 = 12 • BY,BT,BE,YB,YT,YE,TB,TY,TE,EB,EY,ET • P(n,0) = 1 • P(n,n-1) = P(n,n) = n! • P(n,1) = n

15. Calculating Permutations and Combinations of sets mod CALC{ pr(FACT) op permCalc : Int Int -> Int op combCalc : Int Int -> Int vars N R : Int -- Compute permutation where order matters abc =/= bac -- A permutation is an ordered combination. -- perm calculates how many ways R items can be selected from N items eq permCalc(N , R) = fact(N) quo fact(N - R) . -- combination of N things taking R at a time -- Note extra term in divisor. eq combCalc(N , R) = fact(N) quo (fact(N - R) * fact(R)) .} open CALC -- Permutation from 10 items taking 7 at a time red permCalc(10,7) . – gives 604800 -- Combination from 10 items taking 7 at a time red combCalc(10,7) . – gives 120

16. Permutation with repetition of a set • An r-permutations is a permutation that allows repetition in the r-permutation. Here are all the 2-permutation of the letters in SON: SS,SO,SN,OS,OO,ON,NS,NO,NN. • Given a set of size n, in constructing an r-permutation with repetition, for each element we have n choices. • (16.6) The number of r permutations with repetition of a set of size n is nr, repetition is allowed in the r-permutation notin the original set.

17. Permutation of a bag • A bag may have duplicate elements. • Transposition of equal (or duplicate) elements in a permutation does not yield a different permutation e.g. AA=AA. • Hence, there will be fewer permutations of a bag than a set of the same size. The permutations on the set {S,O,N} and the bag M,O,M are: • {S,O,N} = SON,SNO,OSN,ONS,NSO,NOS size=6 • M,O,M = MOM,MMO,OMM size=3

18. Permutation of a bag: General Rule • (16.7) The number of permutations of a bag of size n with kdistinct elements occurring n1, n2, n3,.. nk times is: n! n1!  n2!  n3! ...  nk!

19. CafeOBJ permutation of a Set & Bag • Calc. size of {S,O,N} example • red permCalc(3,3) gives 6 • Calc. size of MOM example red fact(3) quo (fact(1) * fact(2)) . • O occurs once, M twice, gives 3

20. Permutation of a bag • Consider the permutation of the 11 letters of MISSISSIPPI. M occurs 1 time, I occurs 4 times, S occurs 4 times, and P occurs 2 times. red fact(11) quo (fact(1) * fact(2) * fact(4) * fact(4)) .

21. Permutation of a bag • O a single permutation • M1,O, M2 , label the two copies of M. • We could distinguish the Ms. M1M2O,M2M1O,M1OM2,M2OM1,OM1M2,OM2M1,

22. Combinations of a Set • An r-combination of a set is a subset of size r. A permutation is a sequence while a combination is a set.

23. 2-Permutations & 2-Combinations of a Set • The 2-permutations (seq.) of SOHN is: SO,SH,SN,OH,ON,OS,HN,HS,HO,NS,NO,NH • The 2-combinations (set) of SOHN is: {S,O},{S,H},{S,N},{O,H},{O,N},{H,N}

24. Combinations of a Set • The binomial coefficient, “n choose r is written”:

25. Pascal’s Triangle Beginning with row 0 and place 0, the number 20 appears in row 6, place 3. In CafeOBJ we can check this. red combCalc(6,3) . – gives 20 red combCalc(7,4) . – gives 35 red combCalc(7,3) . – gives 35

26. Special Combinations of a Set Generally we label N choose R as:

27. Calculating factorial and division

28. Calculating "n choose k". Simplifying

29. Combinations of a Set • (16.10) The number of r-combinations of n elements is • A student has to answer 6 out of 9 questions on an exam. How many ways can this be done?

30. Combinations with repetitions of a Set • An r-combination with repetitions of a set S of size n is a bagof size r all of whose elements are in S. An r-combination of a set is a subset of that set; an r-combination with repetition of a set is a bag, since its elements need not be distinct.

31. Combinations with repetitions of a Set • For example, there are 62-combinations with repetition of SON are the bags: • S,O,S,N,O,N,S,S,O,O,N,N • On the other hand, there are 92-permutations with repetition are the sequences: • <S,S>,<S,O>,<S,N>,<O,S>,<O,O>,<O,N>,<N,S>,<N,O>,<N,N> Note SO and OS are distinct permutations

32. Combinations with repetitions of a Set • (16.12) The number of r-combinations with repetition of a set of sizen is: Combination size Repetitions size

33. Combinations with repetitions of a Set • Suppose 7 people each gets either a burger, a cheese burger, or fish (3 choices). How many different orders are possible? The answer is the number of 7-combinations with repetition of a set of 3 elements.

34. Rule of sum and product • A class has 55 boys and 56 girls. What is the total number of students in the class, and how many different possible boy girl pairs are there? • Two disjoint sets, boys and girls, rule of sum implies 55+56=111 students. The rule of product says 55  56 = 3080.

35. Rule of sum and product • A student can pass the language requirement on a course by • (i) gaining proficiency in French, German, or Japanese. • (ii) gaining minimal qualification, which involves two semester of (ii)(a) German, Japanese, or Italian and (ii)(b) two semesters of Korean or Hindi. • In how many different ways can the language requirement be satisfied?

36. Rule of sum and product (i)P=F or G or J (ii)S= J(G,J) or I and K or H • The set P of ways in which proficiency can be gained has 3 elements. Let the set S represent the way in which minimal qualification can be satisfied. Each element of S is a pair whose first element is either French, German, Japanese, or Italian and whose second element is either Korean or Hindi. The rule of products gives #S=42=8. Adding these using the rule of sums gives #P+#S=3+8=11

37. Rule of sum and product • In how many different ways can the language requirement be satisfied? • #Proficiency = 3 • #MinimalQualification = 4  2 = 8 • #P + #M = 8 + 3 = 11

38. Example • One bag contains a red ball and a black ball (2). A second bag contains a red ball, a green ball, and a blue ball (3). A person randomly picks first a bag and then a ball. In what fraction of cases will a red ball be selected? • #PossibleSelections = 2+3 = 5 • #PossibleRed = 2 • Fraction of red picked = 2/5

39. Permutations • How many permutations of the letters are there in the following words: • LIE: n=3, 3! = 6 • BRUIT: n=5, 5! = 120 • CALUMMNY: n=7, 7!=5040

40. Permutations of a bag • A coin is tossed 5 times, landing Head or Tails to form an outcome. One possible outcome is HHTTT. • Are we choosing from a set or a bag? • Is the permutation a set or a sequence? • How many possible outcomes are there? • How many outcomes have one Head? • How many outcomes contain at most one Head?

41. Permutations of a bag How many possible outcomes are there? Rule of product giving 25=32 possible outcomes.

42. Permutations of a bag How many outcomes have one Head? Permutation of a bag with 1 Head and four Tails.

43. Permutations of a bag • How many outcomes contain at most one Head? • One Head • No Heads • At most one Head 1 + 5 = 6 (rule of sums)

44. Combinations of Set • A chairman has to select a committee of 5 from a facility of 25. How many possibilities are there? • How many possibilities are there if the chairman should be on the committee?

45. Permutations & Combinations in Excel • In EXCEL • =PERMUT(6,2) • =COMBIN(6,2)

46. The Pigeonhole Principle

47. The Pigeonhole Principle • (16.43) If more than n pigeons are placed in n holes, at least one hole will contain more than one pigeon. • With more than n pigeons in n holes the average number of pigeons per hole is greater than one. • The statement “at least one hole will contain more than one pigeon” is equivalent to “the maximum number of pigeons in any whole is greater than one”.

48. Bags • For each day of the week let the bagS contain the number of people whose birthday is on that day. There are 8 people. • M T W T F S S • 1, 1, 1, 1, 1, 1, 2 • As a set this would be {1,2}.

49. The Pigeonhole Principle • Abstracting from pigeons and holes. • Let av.S denote the average number of elements in bag S. • Let max.S denote the maximum number of elements in bag S. • av.S > 1 implies max.S > 1 • (16.45) Pigeonhole Principle. • av.S  max.S

50. The Pigeonhole Principle • (16.46) Pigeonhole Principle. av.S  max.S • Where 3.1 = 4 ceiling of real number

More Related