Lecture on Counting

advertisement
Lecture on Counting
Example: Codeword. How many different codewords are there if
1. the codeword has length 1: it is either a letter or a digit. ANS: 10+26
2. the codeword has length 2: Any 2 numbers: 102 ; Any 2 letters: 262 ; Any 2 number or any
two letters, but not both: 100 + 262 ; Any 2 letter or digit: 362 .
3. 8-bit codeword: 368
4. At least 8 characters, but no more than 12: 368 + 369 + · · · + 3612 .
Rules used:
Theorem 1 (The Product Rule). Suppose that a procedure can be broken down into a sequence of
k tasks, If there are n1 ways to do the first task, n2 ways to do the second task, ..., nk ways to do
the nk -th task, then there are n1 n2 . . . nk ways to do the procedure.
Theorem 2 (the Sum Rule). 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 the set of n2 ways, then there are n1 + n2 ways to
do the task.
Another way to see them:
1. Product rule: |A × B| = |A| × |B|.
2. Sum rule: If A and B are disjoint, then |A ∪ B| = |A| + |B|.
Also important:
1. |Ā| = |U| − |A|,
2. |A ∪ B| = |A| + |B| − |A ∩ B|
Examples.
Exercise 1. Find the number of binary strings of length n.
ANS: 2n .
Exercise 2. Let A be a set with n elements. How many subsets does A have?
ANS: 2n , since we can identity a subset with its ”membership sequence”. Assume A =
{a1 , a2 , . . . , an } For a subset B, define B ↔ (x1 , x2 , . . . , xn ) where xi = 1 if ai ∈ B, and xi = 0
otherwise.
Exercise 3. Assume |A| = a, and |B| = b. How many functions are there from A to B? (both are
finite)
ANS: How many ways to do the assignment? ba .
Exercise 4. Assume |A| = a, and |B| = b. How many 1-1 functions from A to B?
ANS: b(b − 1)(b − 2)...(b − a + 1).
Exercise 5. How many functions are not 1-1?
ANS: ba − b(b − 1) . . . (b − a + 1).
How about trinary strings of length n? List of n black/white ball? etc.
1
Permutations and Combinations
Let A be a set of size n. An r-permutation of A is an ordered arrangement of r elements of A.
i.e., a sequence (x1 , x2 , . . . , xr ) such that xi ∈ A, and there is no repetition.
n-permutation is simply called permutation.
Theorem 3. The number of r-permutations of a set with n element is
P (n, r) = n(n − 1) . . . (n − r + 1) =
n!
.
(n − r)!
Note that P (n, n) = n!. and 0! = 1.
Exercise 6. How many ways/results of the following?
1. Select a first prize winner, a second prize winner, and a third prize winner from 100 entries?
(P (100, 3).
2. 8 runners in a race. How many possible outcome? (no ties). P (8, 8) = 8!.
3. Itinerary among 8 cities, starting from New York City? 7!.
4. Permutations of A, B, C, D, E, F, G, H containing segment ABC? 6!.
5. 10 pictures, want 4 to put into a frame (2 × 2). How many ways? P (10, 4). note: “ordered”
means “distinguishable”. Not “linear”.
An r-combination of elements of a set A is an unordered
selection of r elements from the set.
i.e., an r-element subset. We denote by C(n, r) or nr the number of r-combinations.
Theorem 4. The number of r-combinations of a set with n element is
C(n, r) =
P (n, r)
n!
=
.
P (r, r)
r!(n − r)!
Proof. Double counting the number of r-permutations and show that C(n, r)P (r, r) = P (n, r).
Note: C(n, 0) = 1, C(n, 1) = 1, C(n, n) = n, C(n, n − 1) = n.
Combinatorial explain: C(n, r) = C(n, n − r).
Exercise 7.
1. Select 5 players from a team of 10? C(10, 5)
2. Select 5 players from a team of 10, and assign of them as Captain. C(10, 5)C(5, 1) or
C(10, 1)C(9, 4).
3. Number of binary string of length n with exactly r 1’s: choose r positions out of n and put 1
there. So C(n, r).
4. Number of strings of characters A, B, C with exactly r A’s: C(n, r)2n−r .
5. Number of ways to choose 3 integers from {1, 2, . . . , 100} such that a1 < a2 < a3 ? – It just
needs to choose 3 different numbers. So C(100, 3).
6. Number of ways to choose 3 integers from {1, 2, . . . , 100} such that a1 ≤ a2 ≤ a3 ? – A trick:
consider a1 , a1 + 1, a2 + 2. These three numbers are distinct, from 1 to 102. Hence C(102, 3).
Think: how about choose 3 out of 100 such that the difference is at least 10?
2
Generaized Permutations and Combinations
We have that
1. The number of k-permutation of a set of n elements is P (n, k) = n!/(n − k)!.
2. The number of k-combination of a set of N elements is C(n, k) = N !/(k!(n − k)!).
The distinction is “ordered” vs “unordered”.
Example 5. How many ways you can put n black and white balls in a row, such that there are
exactly k black balls?
It seems like an ordered problem: balls are listed in a line. When exchanging two balls of
different colors, the arrangement is different. But if you exchange two balls of the same color, you
still have the same arrangement.
Change the point of view: Look at the positions. Which positions have black balls? – Such
positions make a set of k elements out of n possible positions. It it k-combination of n elements.
Hence the answer is C(n, k).
We need to analyse the problem, and try different approaches.
Example 6. How many ways can you put 10 red balls, 20 blue balls and 30 white balls in a row?
Analysis:
60 position, choose 10 for red, then 20 for blue, then the rest for white. Answer is
.
60
10,20,30
Theorem 7 (Permutation with indistinguishable objects). The number of different permutations
of n objects, where there are n1 many of type 1, n2 many of type 2, ..., and nk many of type k is
n
n!
=
n1 , n2 , . . . , nk
n1 !n2 ! . . . nk !
Example 8.
1. Different strings can be made by reordering the letters of the word “SUCCESS”?
2. Different strings can be made by reordering the letters of the word “MISSISSIPPI”?
Example 9.
1. Number of ways to put n distinct marbles into k boxes? – k n
2. Number of ways to put n different marbles into k boxes such that there are ni many in the
ith box?
Solution: Choose n1 , put into Box 1; then choose n2 , put into Box 2, etc.
(Also think of the “box-sequence”. )
3. (Hard!) Number of ways to put n identical marbles into k different boxes?
We have a new problem: Combination with repetitions.
1) Order 10 ice cream cones, choices are “vanilla, chocolate, and strawberry. How many different
orders?
– What is counted as an order? Only the number in each kind is needed. So it is V +C +S = 10.
number of non-negative integer solutions.
2) Make a fruit plate of 20 pieces from Apply, Orange, and Pears. How many ways?
The answer is the non-neg integer solution of A + O + P = 20.
3) How many ways to put 12 idential markers into 4 different boxes.
Let xi be the number of markers in box i. Then we need integer solution of x1 +x2 +x3 = x4 = 12.
3
4) Give 15 pingpang balls to 5 kids: x1 + · · · + x5 = 15.
Technique: How to count the number of non-negative integer solutions of the equation
x1 + x2 + · · · + xn = r
Use n−1 bars and r balls. Count the number of permutations: C(n+r−1, r) = C(n+r−1, n−1).
So we can answer the above questions.
Variations of the integer solutions
(1) Solutions with lower bound: xi ≥ ai . Method: Change of variable, let yi = xi P
− ai .
(2) Inequality x1 + · · · + xn ≤ r. Method: introduce the difference y = r − ni=1 . Then
x1 + · · · + xn + y = r.
More examples:
1. Number of ways to choose 6 cookies from a cookie stand, which has 4 different kinds. (C(6 +
4 − 1, 6).
2. Number of ways to give 15 pingpang balls to 5 kids, such that each of them has at least one.
x1 + · · · + x5 = 15, and xi ≥ 1. Let yi = xi − 1. Then y1 + · · · + y5 = 10. Answer: C(14, 4).
3. Number of the different terms in the expansion of (y1 + y2 + · · · + yn )r after like terms are
combined.
Each term looks like
y!a1 y2q2 · · · ynan
where a1 + · · · + an = r and ai are nonnegative. So C(n + r − 1, r).
Compare: How many ways to divide n idential markers into k piles? Say, k = 2?
It is hard, and we don’t have a nice, clean formula for it. It is called the Stirling number. For
k = 2, it is #{(a, b) : a ≥ b, a + b = n} The answer is bn/2c is both file are non-empty.
4
Download