Binomial Coefficient Identities/Complements CSE21 Fall 2017, Day 4 Oct 6, 2017 https://sites.google.com/a/eng.ucsd.edu/cse21-fall-2017-miles-jones/
permutation P(n,r) = n(n-1) (n-2) (n-r+1) = Terminology n! (n r)! Counts the number of sequences of r elements from a set of n (without repeats) Counts the number of strings (words) of length r from an alphabet of n letters (without repeats.) combination C(n,r) = n!/ ( r! (n-r)! ) = n n choose r r Counts the number of r-element subsets of a set of size n Counts the number of length n binary strings with exactly r ones. Rosen p. 407-413
Subsets Binary strings We claim that n counts the number of k k-element subsets of a set of cardinality n e.g. 1,2,, n. Length n binary strings with exactly k ones. Can you think of a bijection (one-to-one correspondence) between these two sets of objects? Exercise: 4 2 = 6 Write down all 6 4-element subsets of {1,2,3,4}. Write down all 6 length 4 binary strings with exactly 2 ones.
We claim that n counts the number of k k-element subsets of a set of cardinality n e.g. 1,2,, n. Length n binary strings with exactly k ones. Example: 4 2 = 6 { {1,2},{1,3},{1,4},{2,3},{2,4},{3,4} } { 1100,1010,1001,0110,0101,0011 } Is there a natural way to pair these up? Subsets Binary strings
Fixed-density Binary Strings How many length n binary strings contain k ones? Rosen p. 413 Another way to think about it Out of all the positions {1,2,,n}, how many ways can you choose k of those positions to be ones and n-k of those positions to be zeros?
Examples: Suppose I am picking 7 people from this class to go on a field trip. How many ways can I do this? Suppose I am picking 7 people from this class and each one will go on a field trip on a different day of the week. How many days can I do this? Suppose you are doing a group project with a team of 20 people. You must pick a team leader, a scribe, a treasurer, and a presenter. How many ways can you do this? Suppose you are doing a group project with a team of 20 people and you want to pick 4 of the 20 to go to a conference. How many ways can you do this?
Binomial Coefficient Identities What's an identity? An equation that is always true. To prove LHS = RHS Use algebraic manipulations of formulas. OR Interpret each side as counting some collection of strings, and then prove a statements about those sets of strings.
Symmetry Identity Theorem: Rosen p. 411
Symmetry Identity Theorem: Rosen p. 411 Proof 1: Use formula
Symmetry Identity Theorem: Rosen p. 411 Proof 1: Use formula Proof 2: Combinatorial interpretation? LHS counts number of binary strings of length n with k ones RHS counts number of binary strings of length n with n-k ones
Symmetry Identity Theorem: Rosen p. 411 Proof 1: Use formula Proof 2: Combinatorial interpretation? LHS counts number of binary strings of length n with k ones and n-k zeros RHS counts number of binary strings of length n with n-k ones and k zeros
Symmetry Identity Theorem: Rosen p. 411 Proof 1: Use formula Proof 2: Combinatorial interpretation? LHS counts number of binary strings of length n with k ones and n-k zeros RHS counts number of binary strings of length n with n-k ones and k zeros Can match up these two sets by pairing each string with another where 0s, 1s are flipped. This bijection means the two sets have the same size. So LHS = RHS.
Pascal's Identity Theorem: Rosen p. 418 Proof 1: Use formula Proof 2: Combinatorial interpretation? LHS counts number of binary strings??? RHS counts number of binary strings???
Pascal's Identity Theorem: Rosen p. 418 Proof 2: Combinatorial interpretation? LHS counts number of binary strings of length n+1 that have k ones. RHS counts number of binary strings??? Length n+1 binary strings with k ones
Pascal's Identity Theorem: Rosen p. 418 Proof 2: Combinatorial interpretation? LHS counts number of binary strings of length n+1 that have k ones. RHS counts number of binary strings??? Start with 1 Start with 0
Pascal's Identity How many length n+1 strings start with 1 and have k ones in total? Rosen p. 418 A. C(n+1, k+1) B. C(n, k) C. C(n, k+1) D. C(n, k-1) E. None of the above. Start with 1 Start with 0
Pascal's Identity How many length n+1 strings start with 0 and have k ones in total? Rosen p. 418 A. C(n+1, k+1) B. C(n, k) C. C(n, k+1) D. C(n, k-1) E. None of the above. Start with 1 Start with 0
Pascal's Identity Theorem: Rosen p. 418 Proof 2: Combinatorial interpretation? LHS counts number of binary strings of length n+1 that have k ones. RHS counts number of binary strings of length n+1 that have k ones, using two cases Start with 1 Start with 0
Pascal's Triangle Pascal s triangle is closely related to binomial coefficients C n, k = n k
Pascal's Triangle
What's in a name? Why are they called Binomial Coefficients? Binomial: sum of two terms, say x and y. What do powers of binomials look like? (x+y) 4 = (x+y)(x+y)(x+y)(x+y) = (x 2 +2xy+y 2 )(x 2 +2xy+y 2 ) = x 4 +4x 3 y+6x 2 y 2 +4xy 3 +y 4 In general, for (x+y) n A. All terms in the expansion are (some coefficient times) x k y n-k for some k, 0<=k<=n. B. All coefficients in the expansion are integers between 1 and n. C. There is symmetry in the coefficients in the expansion. D. The coefficients of x n and y n are both 1. E. All of the above.
Binomial Theorem (x+y) n = (x+y)(x+y) (x+y) Rosen p. 416 = x n + x n-1 y + x n-2 y 2 + + x k y n-k + + x 2 y n-2 + xy n-1 + y n Number of ways we can choose k of the n factors (to contribute to x) and hence also n-k of the factors (to contribute to y)
Binomial Theorem (x+y) n = (x+y)(x+y) (x+y) Rosen p. 416 = x n + x n-1 y + x n-2 y 2 + + x k y n-k + + x 2 y n-2 + xy n-1 + y n Number of ways we can choose k of the n factors (to contribute to x) and hence also n-k of the factors (to contribute to y) C(n,k) = x n + C(n,1) x n-1 y + + C(n,k) x k y n-k + + C(n,k-1) xy n-1 + y n
Binomial Theorem Rosen p. 416 x + y 0 = 1 x + y 1 = 1x + 1y x + y 2 = 1x 2 + 2xy + 1y 2 x + y 3 = 1x 3 + 3x 2 y + 3xy 2 + 1y 3 x + y 4 = 1x 4 + 4x 3 y + 6x 2 y 2 + 4xy 3 + 1y 4 x + y 5 = 1x 5 + 5x 4 y + 10x 3 y 2 + 10x 2 y 3 + 5xy 4 + 1y 5 x + y 6 = 1x 6 + 6x 5 y + 15x 4 y 2 + 20x 3 y 3 + 15x 2 y 4 + 6xy 5 + 1y 6
Sum Identity Theorem: Rosen p. 417
Sum Identity Theorem: Rosen p. 417 What set does the LHS count? A. Binary strings of length n that have k ones. B. Binary strings of length n that start with 1. C. Binary strings of length n that have any number of ones. D. None of the above.
Sum Identity Theorem: Rosen p. 417 Proof : Combinatorial interpretation? LHS counts number of binary strings of length n that have any number of 1s. By sum rule, we can break up the set of binary strings of length n into disjoint sets based on how many 1s they have, then add their sizes. RHS counts number of binary strings of length n. This is the same set so LHS = RHS.
Another Counting Problem How many 4 digit strings of digits 0-9 have at least one 0? A. 4 9 3 B. 10 4 9 4 C. 4 9 3 + 6 9 2 + 4 9 + 1 D. 9 3 E. 4 10 3
Another Counting Problem How many 4 digit strings of digits 0-9 have at least one 0? All 4 digit strings of 0-9 All 4 digit strings of 1-9
Counting using the complement Whenever you see at least in the problem description, that is a clue. Count the entire set first. Then count the complement of the set you are interested in. Subtract the two counts.
Counting using the complement Exercise: How many length 4 strings of the digits 0-9 have at least two consecutive digits that are the same?
What is recursion? Solving a problem by successively reducing it to the same problem with smaller inputs. Rosen p. 360
Recurrences A recurrence relation (also called a recurrence or recursive formula) expresses f(n) in terms of previous values, such as f(n-1), f(n-2), f(n-3). Example: f(n) = 3*f(n-1) + 7 f(1) = 2 start tells us how to find f(n) from f(n-1) also need a base case to tell us where to
Some well known recurrences Fibonacci numbers: F 0 = 0, F 1 = 1, for n 2: F n = F n 1 + F n 2 Factorials: 0! = 1, for n 1: n! = n n 1! Summation of integers. S(1) = 1, for n 2: S n = S n 1 + n Rosen P. 158
Closed form Summation of integers. Rosen P. 158 S(1) = 1, for n 2: S n = S n 1 + n What is the closed form of this recursion? A. n B. 2 n C. n(n + 1) D. E. n n+1 n 2 2 2
Two ways to solve recurrences 1. Guess and Check find a closed form Start with small values of n and look for a pattern. Confirm your guess with a proof by induction. 2. Unravel Start with the general recurrence and keep replacing n with smaller input values. Keep unraveling until you reach the base case.
Closed form Summation of integers. Rosen P. 158 S(1) = 1, for n 2: S n = S n 1 + n Guess and check: (induction) Claim: S(n) = n n+1 2 for all n 1.
Closed form Summation of integers. Rosen P. 158 S(1) = 1, for n 2: S n = S n 1 + n Guess and check: (induction) Claim: S(n) = n n+1 2 for all n 1. Base Case: S 1 = 1 = 1 1+1 2 Inductive Hypothesis: Suppose that for some k 1, S k = Inductive Step: We want to show that S k + 1 = (k+1)(k+2) 2 k k+1 2
Closed form Summation of integers. Rosen P. 158 S(1) = 1, for n 2: S n = S n 1 + n S k + 1 = S k + k + 1 k k + 1 = + k + 1 2 k k+1 +2(k+1) = 2 k + 2 k + 1 = 2
Unraveling Solve this recurrence by unraveling: a 1 = 2 a n = 2a n 1 + 2 n for n 2
Unraveling Solve this recurrence by unraveling: a 1 = 2 a n = 2a n 1 + 2 n for n 2 a n = 2a n 1 + 2 n = 2 2a n 2 + 2 n 1 + 2 n = 2 2 a n 2 + 2 n + 2 n = 2 2 2a n 3 + 2 n 2 + 2 n + 2 n = 2 3 a n 3 + 2 n + 2 n + 2 n. = 2 k a n k + k 2 n. (k = n 1) = 2 n 1 a 1 + (n 1)2 n = n2 n
The Tower of Hanoi How many moves?
The Tower of Hanoi Recursive solution: 1) Move the stack of the smallest n-1 disks to an empty pole. 2) Move the largest disk to the remaining empty pole. 3) Move the stack of the smallest n-1 disks to the pole with the largest disk. How many moves? T(n) = # of moves to solve puzzle with n disks
Tower of Hanoi: WHEN Recursive solution: 1) Move the stack of the smallest n-1 disks to an empty pole. 2) Move the largest disk to the remaining empty pole. 3) Move the stack of the smallest n-1 disks to the pole with the largest disk. T(n) = # of moves to solve puzzle with n disks Recurrence? A. T(n) = 2T(n-1) B. T(n) = T(n-1) + 1 C. T(n) = n-1 + T(n) D. T(n) = 2T(n-1) + 1 Base case? A. T(1) = 1 B. T(1) = 2 C. T(0) = 0 D. T(2) = 2
Tower of Hanoi: WHEN But what's the value of T(n)? n T(n) 1 1 2 3 4 5 n Recurrence for T(n): T(n) = 2T(n-1) + 1 T(1) = 1
Tower of Hanoi: WHEN But what's the value of T(n)? n T(n) 1 1 2 3 3 7 4 15 5 31 n?? Is there a pattern we can guess? Recurrence for T(n): T(n) = 2T(n-1) + 1 T(1) = 1
After guessing, we check (i.e., validate) Tower of Hanoi: WHEN Claim: For each positive int n, T(n) = 2 n -1. Proof by induction on n Recurrence for T(n): T(n) = 2T(n-1) + 1 T(1) = 1 (Base case) If n = 1, then T(n) = 1 (according to the recurrence). Plugging n = 1 into the formula gives T(1) = 2 1-1 = 2-1 = 1.
Tower of Hanoi: WHEN Claim: For each positive int n, T(n) = 2 n -1. Proof by induction on n Recurrence for T(n): T(n) = 2T(n-1) + 1 T(1) = 1 (Induction step) Suppose n is a positive integer greater than 1 and, as the induction hypothesis, assume that T(n-1) = 2 n-1-1. We need to show that T(n) = 2 n -1. From the recurrence, T(n) = 2 T(n-1) + 1 = 2 ( 2 n-1 1 ) + 1 = 2 n 2 + 1 = 2 n 1. by the I.H.
Tower of Hanoi: WHEN Another method: UNRAVEL the recurrence: Recurrence for T(n): T(n) = 2T(n-1) + 1 T(1) = 1