Counting
CS 30 : Discrete Mathematics for Computer Science First Semester, AY 2012-2013
https://sites.google.com/a/dcs.upd.edu.ph/nhsh_classes/cs 30
sablay-logo
Nestine Hope S. Hernandez Algorithms and Complexity Laboratory Department of Computer Science University of the Philippines, Diliman nshernandez@dcs.upd.edu.ph updilseal
Day 11
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Combinatorics and Computing
sablay-logo
1
Counting Generalized Permutations and Combinations
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Permutations with Repetition
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Permutations with Repetition
Theorem The number of r-permutations of a set of n objects with repetitions allowed is n . r
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Permutations with Repetition
Theorem The number of r-permutations of a set of n objects with repetitions allowed is n . r
sablay-logo
Example: How many strings of length 5 can be formed from the English alphabet?
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Permutations with Indistinguishable Objects
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Permutations with Indistinguishable Objects
Theorem The number of di erent permutations of n objects, where there are n indistinguishable objects of type 1, n indistinguishable objects of type 2, . . ., and n indistinguishable objects of type k, is 1
2
k
sablay-logo
n!
n !n ! ¡ ¡ ¡ n ! 1
2
k
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Permutations with Indistinguishable Objects
Theorem The number of di erent permutations of n objects, where there are n indistinguishable objects of type 1, n indistinguishable objects of type 2, . . ., and n indistinguishable objects of type k, is 1
2
k
sablay-logo
n!
n !n ! ¡ ¡ ¡ n ! 1
2
k
Example: How many di erent strings can be made by reordering the letters of the word SUCCESS?
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Combinations with Repetition
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Combinations with Repetition
Example: How many ways are there to select four pieces of fruit from a bowl containing apples, oranges and pears if the order in which the pieces are selected does not matter, only the type of fruit and not the individual piece matters, and there are at least four pieces of each type of fruit in the bowl? 1
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Combinations with Repetition
Example: How many ways are there to select four pieces of fruit from a bowl containing apples, oranges and pears if the order in which the pieces are selected does not matter, only the type of fruit and not the individual piece matters, and there are at least four pieces of each type of fruit in the bowl? How many ways are there to select four bills from a cash box containing P20, P50, P100, P200, P500 and P1000 bills? Assume that the order in which the bills are chosen does not matter, that the bills of each denomination are indistinguishable, and that there are at least ve bills of each type. 1
sablay-logo
2
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Combinations with Repetition
Example: How many ways are there to select four pieces of fruit from a bowl containing apples, oranges and pears if the order in which the pieces are selected does not matter, only the type of fruit and not the individual piece matters, and there are at least four pieces of each type of fruit in the bowl? How many ways are there to select four bills from a cash box containing P20, P50, P100, P200, P500 and P1000 bills? Assume that the order in which the bills are chosen does not matter, that the bills of each denomination are indistinguishable, and that there are at least ve bills of each type. Suppose that a cookie shop has four di erent kinds of cookies. How many di erent ways can six cookies be chosen? Assume that only the type of cookie, and not the individual cookies or the order in which they are chosen, matters. 1
sablay-logo
2
3
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Combinations with Repetition
Example: How many ways are there to select four pieces of fruit from a bowl containing apples, oranges and pears if the order in which the pieces are selected does not matter, only the type of fruit and not the individual piece matters, and there are at least four pieces of each type of fruit in the bowl? How many ways are there to select four bills from a cash box containing P20, P50, P100, P200, P500 and P1000 bills? Assume that the order in which the bills are chosen does not matter, that the bills of each denomination are indistinguishable, and that there are at least ve bills of each type. Suppose that a cookie shop has four di erent kinds of cookies. How many di erent ways can six cookies be chosen? Assume that only the type of cookie, and not the individual cookies or the order in which they are chosen, matters. 1
sablay-logo
2
3
Theorem There are C (n + r − 1, r ) = C (n + r − 1, n − 1) r-combinations from a set with n elements when repetition of elements is allowed. Discrete Mathematics for Computer Science
CS 30
updilseal
dcs-logo
acl-logo
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES:
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES: Example: How many ways are there to distribute hands of 13 cards to each of four players from the standard deck of 52 cards?
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES: Example: How many ways are there to distribute hands of 13 cards to each of four players from the standard deck of 52 cards?
sablay-logo
Theorem The number of ways to distribute n distinguishable objects into k distinguishable boxes so that n objects are placed into box i, i = 1, 2, . . . , k, equals n! n !n ! 路 路 路 n ! i
1
2
k
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES: Example: How many ways are there to distribute hands of 13 cards to each of four players from the standard deck of 52 cards?
sablay-logo
Theorem The number of ways to distribute n distinguishable objects into k distinguishable boxes so that n objects are placed into box i, i = 1, 2, . . . , k, equals n! n !n ! 路 路 路 n ! i
1
2
k
updilseal
How many ways are there to distribute hands of 5 cards to each of four players from the standard deck of 52 cards?
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES:
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES: Example: How many ways are there to place 10 indistinguishable balls into 8 distinguishable bins?
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND DISTINGUISHABLE BOXES: Example: How many ways are there to place 10 indistinguishable balls into 8 distinguishable bins?
sablay-logo
Theorem The number of ways to place r indistinguishable objects into n distinguishable boxes is C (n + r − 1, r ) = C (n + r − 1, n − 1).
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES:
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to put four di erent employees into three indistinguishable o ces, when each o ce can contain any number of employees?
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to put four di erent employees into three indistinguishable o ces, when each o ce can contain any number of employees?
sablay-logo
Stirling numbers of the second kind −1
1X j S (n , j ) = (−1) (j − i ) j! = i j
i
i
n
0
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
DISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to put four di erent employees into three indistinguishable o ces, when each o ce can contain any number of employees?
sablay-logo
Stirling numbers of the second kind −1
1X j S (n , j ) = (−1) (j − i ) j! = i j
i
i
n
0
The number of ways to distribute n distinguishable objects into k indistinguishable boxes equals
updilseal
k
X j
S (n, j )
dcs-logo
=1 acl-logo
Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES:
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to pack six copies of the same book into four identical boxes, where a box can contain as many as six books?
sablay-logo
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to pack six copies of the same book into four identical boxes, where a box can contain as many as six books?
sablay-logo
Observe that distributing n indistinguishable objects into k indistinguishable boxes is the same as writing n as the sum of at most k positive integers in decreasing order.
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to pack six copies of the same book into four identical boxes, where a box can contain as many as six books?
sablay-logo
Observe that distributing n indistinguishable objects into k indistinguishable boxes is the same as writing n as the sum of at most k positive integers in decreasing order. If p (n) is the number of partitions of n into at most k positive integers, then there are p (n) ways to distribute n indistinguishable objects into k indistinguishable boxes. k
k
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
Generalized Permutations and Combinations
Distributing Objects into Boxes
INDISTINGUISHABLE OBJECTS AND INDISTINGUISHABLE BOXES: Example: How many ways are there to pack six copies of the same book into four identical boxes, where a box can contain as many as six books?
sablay-logo
Observe that distributing n indistinguishable objects into k indistinguishable boxes is the same as writing n as the sum of at most k positive integers in decreasing order. If p (n) is the number of partitions of n into at most k positive integers, then there are p (n) ways to distribute n indistinguishable objects into k indistinguishable boxes. k
k
No simple closed formula exists for this number.
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30
Counting
sablay-logo
Questions? See you next meeting!
updilseal
dcs-logo
acl-logo Discrete Mathematics for Computer Science
CS 30