Title: Computing Fundamentals 2 Lecture 5 Combinatorial Analysis
1Computing Fundamentals 2Lecture 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
2Combinatorial Analysis
- Counting
- Permutations
- Combinations
- The Pigeonhole Principle
- Examples
3Combinatorial 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.
4Rules of Counting
- Rule of sums The size of the union on n finite
pair wise disjoint sets is the sum of their
sizes. - Rule of product 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.
5Product 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
6Permutation of a set
- A permutation of a set of elements is a linear
ordering (or sequence) of the elements e.g. - 1,4,5
- Permutation 1 1, 4, 5
- Permutation 2 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 factorial n, written n!
7Calculating 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) .
8Permutation 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
9Calculating 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
10Permutation with repetition of a set
- An r-permutations is a permutation that allows
repetition. 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 permutation not in the original
set.
11Permutation 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. AAAA. - 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
- ?M,O,M? MOM,MMO,OMM
12Permutation of a bag General Rule
- (16.7) The number of permutations of a bag of
size n with k distinct elements occurring n1, n2,
n3,.. nk times is - n!
- n1! ? n2! ? n3! ... ? nk!
13Permutation of a 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
14Permutation 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)) .
15Permutation of a bag
- ?O? a single permutation
- ?M1,O, M2? , label the two copies of M.
- We can distinguish the Ms.
- M1M2O,M2M1O,M1OM2,M2OM1,OM1M2,OM2M1,
16Example 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. - 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
17Combinations of a Set
- The binomial coefficient, n choose r is
written
18Pascals 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 See web page http//cob.isu.edu/parkerKR
/courses/CIS220/Programs/P9_pascalsTriangle.htm
19Special Combinations of a Set
20Calculating factorial and division
21Calculating "n choose k".
22Combinations 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?
23Combinations with repetitions of a Set
- An r-combination with repetitions of a set S of
size n is a bag of 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.
24Combinations with repetitions of a Set
- For example, the 2-combinations with repetition
of SON are the bags - ?S,O?,?S,N?,?O,N?,?S,S?,?O,O?,?N,N?
- On the other hand, the 2-permutations with
repetition are the sequences - SS,SO,SN,OS,OO,ON,NS,NO,NN
Note SO and OS are distinct permutations
25Combinations with repetitions of a Set
- (16.12) The number of r-combinations with
repetition of a set of size n is
Combination size
Repetitions size
26Combinations 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.
27The Equivalence of three statements
- (16.13) The following numbers are equal
- The number of integer solutions of the equation
x1x2x3...xnr. - The number of r-combinations with repetition of a
set of size n. - The number of identical ways r identical objects
can be distributed among n different containers.
28Rule 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 5556111 students. The rule of product
says 55 ? 56 3080.
29Rule 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?
30Rule of sum and product
- 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
S4?28. Adding these using the rule of sums
gives PS3811
31Rule 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
32Rule of sum and product
- 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 23 5
- PossibleRed 2
- Fraction of red picked 2/5
33Permutations
- How many permutations of the letters are there in
the following words - LIE n3, 3! 6
- BRUIT n5, 5! 120
- CALUMMNY n7, 7!5040
34Permutations of a bag
- A coin is tossed 5 times, landing Head or Tails
to form an outcome. One possible outcome is
HHTTT. - How many possible outcomes are there?
- How many outcomes have one Head?
- How many outcomes contain at most one Head?
35Permutations of a bag
- How many possible outcomes are there?
- Rule of product giving 2532 possible outcomes.
36Permutations of a bag
- How many outcomes have one Head?
- Permutation of a bag with 1 Head and four Tails.
37Permutations of a bag
- How many outcomes contain at most one Head?
- One Head
- No Heads
- At least one Head 1 5 6 (rule of sums)
38Combinations 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 chair
should be on the committee?
39The 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.
40The 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
41The Pigeonhole Principle
- (16.46) Pigeonhole Principle.
- av.S ? max.S
- Where
- 3.1 4 ceiling of real number
42Example The Pigeonhole Principle
- (16.47) Prove that in a room of eight people, at
lease two of them have birthdays on the same day
of the week. - Let bag S contain, for each day of the week the
number of people in the room whose birthday is on
that day. The number of people is 8 the number of
days is 7.
43Example The Pigeonhole Principle
44Example 2 The Pigeonhole Principle
- Suppose S is a set of six integers, each between
1 and 12 inclusive. Prove that there must be two
distinct nonempty subsets of S that have the same
sum. - Proof The sum of all the elements of S is at
most 789101112 57. So the sum of the
elements of any nonempty subset of S is at least
1 and at most 57 there are 57 possibilities. But
there are 261 63 nonempty subsets of S. Hence
there must be two with the same sum.