Chapter 5 Combinatorics

advertisement
Chapter 5 Combinatorics
What is counting?
Find the number of ternary strings of length n.
Consider ternary strings of length 5.
a. How many begin with a 2?
b. How many begin and end with the same symbol?
c. How many begin and end with different symbols?
More examples
Connecting Computers
5 computers, each directly connected to all of the others
210 or 1024 processors connected in the following way:
How many ways are there to move two of 20 computers to another
lab?
Binary trees
More Counting Examples
Example 1: Number of bit strings of length 8 that begin with a 1
Example 2: Number of bit strings of length 8 with at least two 1’s.
Example 3: The number of license plates using
a) 2 letters followed by 4 digits:
b) 2 digits followed by 4 letters:
c) either a or b
Example 4: Number of ternary strings of length 5 begin with 11 or
end with 222
Example 5: Counting functions again
Still more counting examples
Example 6: How many ternary strings of length 11 are palindromes?
Example 7: You are forming seven-letter words consisting of lower
case letters from the English alphabet. How many such words can
be formed if
a. all letters are distinct?
b. the word contains exactly one vowel and all letters are distinct?
c. the word contains at least one vowel?
d. the word contains four consonants and three vowels with all
vowels at the beginning of the word, all letters distinct?
The Sum and Product Rules
The Sum Rule: Given tasks T1, T2, …, Tk, with task Ti having exactly
ni possible outcomes, the number of ways to perform one of these k
tasks is n1 + n2 + … + nk.
The Product Rule: Given tasks T1, T2, …, Tk, with task Ti having
exactly ni possible outcomes, the number of possible ways to
perform all of these k tasks is n1•n2• …•nk.
Examples:
1. Electronic lock with 7-digit code
More Examples
2. At a local deli you can choose from six kinds of soda, 10 kinds of
sandwiches and 12 desserts. How many ways are there to order:
a. a sandwich
b. exactly one item
c. a full meal (soda, sandwich and dessert)
d. any two items (repetition allowed)
e. any two distinct items
f. items of two different kinds
3. In Fortran, an identifier is a character string with length 1 to 7.
The first character must be a letter. How many different
identifiers are there?
Still More Examples
4. You have a ten question multiple choice test in which there are
five possible choices for each answer. How many possible
answer keys are there if
a. there are no restrictions
b. the answer to the first question is ‘a’
c. exactly one question has ‘a’ as the correct answer
d. exactly two questions have ‘a’ as the correct answer
e. exactly one question has ‘a’ as the correct answer and
exactly one has ‘b’ as the correct answer
f. exactly one answer is ‘a’, exactly one answer is ‘b’, and exactly
one answer is ‘c’
Two basic variations:
1) order in which the objects are chosen or placed is significant
2) order in which the objects are chosen or placed is not significant
Permutations and Combinations
Number of orders in which the letters of the alphabet can be placed
A permutation of a set of n distinct objects is an ordered
arrangement of the n objects. If only r of the n objects are used we
have an r-permutation. Notation: P(n, r)
P(n, r) =
P(n, n) =
P(n, 0) =
Example 1: Consider the set {a, b, c, d, e, f}
# of ways to form 4-character string
# of ways to form 4-character string if no letter is repeated
Example 2: How many four-digit numbers
contain only odd digits
contain only even digits
do not contain 0
have all digits distinct
contain at least one 3
contain exactly one 3 with all digits distinct
Combinations
An r-combination is
Notation: C(n, r) or
Combinatorial Identities
C(n, r) = C(n, n-r)
n
Σ C(n, i) = 2n
i=0
Examples
Example 1: Menu with 6 sodas, 10 sandwiches, 12 desserts. How
many ways are there to order 3 sodas, 5 sandwiches and 2 desserts,
all different?
Example 2: A committee is chosen from a group of 4 men and 6
women.
a) In how many ways can a committee of size three be chosen?
b) In how many ways can a committee of size three be chosen if
there must be 1 man and 2 women?
Example 3: A student must answer 10 of 13 questions on an exam.
How many ways can he or she take the exam if
a. there are no restrictions
b. the first two questions must be answered
c. the first or second question, but not both must be answered
d. exactly three of the first five questions must be answered
e. at least three of the first five questions must be answered
More examples
Example 4: How many five card poker hands contain
a. 2 spades and 3 red cards
b. 2 cards each of two ranks
c. all red cards with two cards each of two ranks
d. exactly one queen and exactly three spades
e. contain at least one ace?
Why won’t the following approach work?
Example 5: How many ternary strings of length 10 are there with
a. exactly two 0’s, three 1’s and five 2’s
b. exactly two 0’s, three 1’s and five 2’s with each 1 immediately
preceded by a 2.
Example 6: You invite nine friends to join you at dinner. How many
ways can the ten of you be seated around a circular table?
The Powerball Lottery
Rules of the Game
Ways to Win
Counting the number of ways to win
The number of possible powerball tickets is:
Variations of the basic problem
Example—the Pick Three Game
Rules:
Ways to win:
Inclusion/Exclusion Examples
1. Let S = {a, b, c, d, e, f}. How many strings of length 5 begin or
end with a?
2. Find the number of positive integers  100 that are even or
divisible by 7.
3. Find the number of four digit numbers that have exactly one 3.
Case 1:
Case 2:
4. How many powerball tickets have white numbers 13 or 43 but
not both?
More Examples
Example 5: Let S = {1, 2, …, 10}. The number of subsets of S that
a. contain exactly 4 odd numbers is
b. contain exactly 6 elements, exactly two of which are even is
c. contain 2 but not 5 is
Example 6: Find the number of bit strings of length 10 that
contain 5 consecutive 0’s or 5 consecutive 1’s.
Example 7: How many strings of length 6 can be made from the
letters in the set {a, b, c, d, e, f} which contain exactly one c or
exactly one d.
Example 8: A fly travels along a 44 grid moving from the lower
left to the upper right corner. If no diagonal moves (or backward
moves) are allowed, how many paths are there which could be
taken?
Download