Alphastar Counting Basic AIME Course

Citation preview

Chapter 1

Basic Counting Techniques 1.1

Notes

1.2

Review

For completeness, we review some basic definitions and facts that you should know: ˆ For integer n ≥ 0, the quantity n! = n(n − 1)(n − 2) . . . (2)(1) denotes the number of permutations of the set {1, 2, . . . , n}, with 0! = 1.  n! ˆ Given 0 ≤ k ≤ n, the quantity nk = (n−k)!k! denotes the number of size-k subsets of {1, 2, . . . , n}, or equivalently, the number of ways to choose k people from a group of n where ordering is unimportant.

1.3

Casework and Complementary Counting

Two basic approaches for counting problems are casework and complementary counting. Unfortunately, “casework” means exactly what it means: subdivide a counting problem into manageable, organized cases. Complementary counting is a technique where we count the number of outcomes that we don’t want, then subtract that result from the total number of possible outcomes. Look for words such as “at least” or “not” - these often signal that complementary counting may be a viable method. Example 1.3.1. (AIME II 2007 #1) A mathematical organization is producing a set of commemorative license plates. Each plate contains a sequence of five characters chosen from the four letters in AIME and the four digits in 2007. No character may appear in a sequence more times than it appears among the four letters in AIME or the four digits in 2007. A set of plates in which each possible sequence appears exactly once contains N N license plates. Find 10 . 4

MC40C Chapter 1.

Basic Counting Techniques

Solution. Let’s break it down into cases based on how many letters there are. If there are 4, there are 3 ways to choose the digit and 5! ways to arrange them, for a subtotal of 360. If there are 3, there are 4 ways to choose them and 3 ways to choose two different digits, plus one way to choose the same digits. This gives a subtotal of 4(3 · 120 + 60) = 1680. If there are 2, there are 6 ways to choose them and 1 way to choose three different digits and 2 ways otherwise. This gives a subtotal of 6(120 + 2 · 60) = 1440. Finally, if there is only 1 letter, there are 4 ways to choose it and 60 ways to arrange it. This gives N = 360 + 1680 + 1440 + 60 = 3540 ⇒ 354 . Example 1.3.2. (AIME I 2002 #1) Many states use a sequence of three letters followed by a sequence of three digits as their standard license-plate pattern. Given that each threeletter three-digit arrangement is equally likely, the probability that such a license plate will contain at least one palindrome (a three-letter arrangement or a three-digit arrangement that reads the same left-to-right as it does right-to-left) is m/n, where m and n are relatively prime positive integers. Find m + n. Solution. We just need to calculate the probability that neither the digits nor the letters form a palindrome. In both cases, the third character just cannot equal the first. So the 9 7 probability is 1 − ( 10 )( 25 26 ) = 52 ⇒ 59 .

1.4

Examples

1. (HMMT Feb-2018-Combinatorics-1) Consider a 2 × 3 grid where each entry is one of 0, 1, and 2. For how many such grids is the sum of the numbers in every row and in every column a multiple of 3? One valid grid is shown below.



1 2 0 2 1 0



2. (PUMaC-2012-Team-2.1.3) Suppose you draw 5 vertices of a convex pentagon (but not the sides!). Let N be the number of ways you can draw at least 0 straight line segments between the vertices so that no two line segments intersect in the interior of the pentagon. What is N − 64? (Note what the question is asking for! You have been warned!) 3. (AIME-2010-I-7) Define an ordered triple (A, B, C) of sets to be minimally intersecting if |A ∩ B| = |B ∩ C| = |C ∩ A| = 1 and A ∩ B ∩ C = ∅. For example, ({1, 2}, {2, 3}, {1, 3, 4}) is a minimally intersecting triple. Let N be the number of minimally intersecting ordered triples of sets for which each set is a subset of {1, 2, 3, 4, 5, 6, 7}. Find the remainder when N is divided by 1000. Note: |S| represents the number of elements in the set S. 5

MC40C Chapter 1.

Basic Counting Techniques

4. (HMMT Feb-2016-Guts-6) Consider a 2 × n grid of points and a path consisting of 2n − 1 straight line segments connecting all these 2n points, starting from the bottom left corner and ending at the upper right corner. Such a path is called efficient if each point is only passed through once and no two line segments intersect. How many efficient paths are there when n = 2016? 5. (AIME-2016-I-8) For a permutation p = (a1 , a2 , . . . , a9 ) of the digits 1, 2, . . . , 9, let s(p) denote the sum of the three 3-digit numbers a1 a2 a3 , a4 a5 a6 , and a7 a8 a9 . Let m be the minimum value of s(p) subject to the condition that the units digit of s(p) is 0. Let n denote the number of permutations p with s(p) = m. Find |m − n|. 6. (HMMT Feb-2010-Combinatorics-4) Manya has a stack of 85 = 1 + 4 + 16 + 64 blocks comprised of 4 layers (the kth layer from the top has 4k−1 blocks; see the diagram below). Each block rests on 4 smaller blocks, each with dimensions half those of the larger block. Laura removes blocks one at a time from this stack, removing only block that currently have no blocks on top of them. Find the number of ways Laura can remove precisely 5 blocks from Manya’s stack (the order in which they are removed matters).

1.5

Exercises

1. (HMMT Feb-2016-Combinatorics-3) Find the number of ordered pairs of integers (a, b) such that a, b are divisors of 720 but ab is not. 2. (CHMMC-2010 Fall-Individual-1) Susan plays a game in which she rolls two fair standard six-sided dice with sides labeled one through six. She wins if the number on one of the dice is three times the number on the other die. If Susan plays this game three times, compute the probability that she wins at least once. 3. (AIME-2008-I-7) Let Si be the set of all integers n such that 100i ≤ n < 100(i + 1). For example, S4 is the set 400, 401, 402, . . . , 499. How many of the sets S0 , S1 , S2 , . . . , S999 do not contain a perfect square?

6

MC40C Chapter 1.

Basic Counting Techniques

4. (AIME-2012-II-7) Let S be the increasing sequence of positive integers whose binary representation has exactly 8 ones. Let N be the 1000th number in S. Find the remainder when N is divided by 1000. 5. (HMMT Feb-2010-Combinatorics-2) How many positive integers less than or equal to 240 can be expressed as a sum of distinct factorials? Consider 0! and 1! to be distinct. 6. (CHMMC-2014-Individual-2) Suppose in your sock drawer of 14 socks there are 5 different colors and 3 different lengths present. One day, you decide you want to wear two socks that have both different colors and different lengths. Given only this information, what is the maximum number of choices you might have?

7

Chapter 2

Counting Sets & PIE 2.1

Notes

A set is a collection of distinct objects, called elements (often numbers, variables, functions, other sets, etc.). The empty set is the set containing no elements, and is denoted by ∅. For a set S, we define the cardinality of S (often abbreviated as |S|) to be the size of S, or the number of elements in S. |S| = 0 if and only if S = ∅. Definition 2.1.1 (Union and Intersection). Given two sets A and B, the union of A and B, denoted A ∪ B, is the set of all elements which belong to either A or B (or both). The intersection of A and B, denoted A ∩ B, is the set of all elements which belong to A and B. The Principle of Inclusion and Exclusion, or PIE, generalizes the principle behind counting with Venn Diagrams. In the most simple case, suppose we know the cardinality of finite sets A, B, and A ∩ B, and we want to know the size of A ∪ B. Then |A| + |B| counts everything in A ∪ B but it overcounts the elements in A ∩ B. Subtracting |A ∩ B|, we end up with the formula |A ∪ B| = |A| + |B| − |A ∩ B|. Now consider the case with three finite sets A, B, C, in which we want to find |A∩B∩C|. If we add |A| + |B| + |C|, then each of the intersections A ∩ B, B ∩ C, C ∩ A is counted twice. If we subtract each of them, then elements in A ∩ B ∩ C are counted 3 − 1 − 1 − 1 = 0 times, so it needs to be added back in. Thus the formula is |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |B ∩ C| − |C ∩ A| + |A ∩ B ∩ C|. In general, if there are n sets, the formula is: Theorem 2.1.2 (Principle of Inclusion-Exclusion). If (Ai )1≤i≤n are finite sets, then:

8

MC40C Chapter 2.

Counting Sets & PIE

n n [ X X X |Ai | − |Ai ∩ Aj | + |Ai ∩ Aj ∩ Ak | − · · · + (−1)n−1 |A ∩ · · · ∩ An | . Ai = i=1

i=1

i a4 > a5 > a6 and a6 < a7 < a8 < a9 < a10 < a11 < a12 An example of such a permutation is (6, 5, 4, 3, 2, 1, 7, 8, 9, 10, 11, 12). Find the number of such permutations. 2. (HMMT Feb-2006-Combinatorics-2) Compute n60 2 X X

···

n60 =0 n59 =0

n3 X n2 X n1 X

1.

n2 =0 n1 =0 n0 =0

3. (HMMT Feb-2012-Combinatorics-3) In the figure below, how many ways are there to select 5 bricks, one in each row, such that any two bricks in adjacent rows are adjacent?

13

MC40C Chapter 3.

Path Counting & Bijections

4. (BMT-2012-Tournament-Round7-P1) How many ways can we arrange the elements {1, 2, ..., n} into a sequence a1 , a2 , ..., an such that there is only exactly one ai , ai+1 such that ai > ai+1 ? 5. (BMT-2012-Tournament-Round4-P6) Link starts at the top left corner of an 12 × 12 grid and wants to reach the bottom right corner. He can only move down or right. A turn is defined a down move immediately followed by a right move, or a right move immediately followed by a down move. Given that he makes exactly 6 turns, in how many ways can he reach his destination? 6. (AIME-2018-II-8) A frog is positioned at the origin of the coordinate plane. From the point (x, y), the frog can jump to any of the points (x + 1, y), (x + 2, y), (x, y + 1), or (x, y + 2). Find the number of distinct sequences of jumps in which the frog begins at (0, 0) and ends at (4, 4).

3.3

Exercises

1. (HMMT Feb-2008-Combinatorics-2) Let S = {1, 2, . . . , 2008}. For any nonempty subset A ∈ S, define m(A) to be the median of A (when A has an even number of elements, m(A) is the average of the middle two elements). Determine the average of m(A), when A is taken over all nonempty subsets of S. 2. (HMMT Feb-2012-Combinatorics-4) A frog is at the point (0, 0). Every second, he can jump one unit either up or right. He can only move to points (x, y) where x and y are not both odd. How many ways can he get to the point (8, 14)? 3. (Brice Huang) How many ways are there to write 10 as the sum of any number of positive integers if different orderings of the same sum are distinguishable? 4. (HMMT Feb-2002-Guts-22) A path of length n is sequence of points (x1 , y1 ), (x2 , y2 ), ..., (xn , yn ) with integer coordinates such that for all i between 1 and n − 1 inclusive, either: (a) xi+1 = xi + 1 and yi+1 = yi (in which case we say the ith step is rightward ), or (b) xi+1 = xi and yi+1 = yi + 1 (in which case we say the ith step is upward ). This path is said to start at (x1 , y1 ) and end at (xn , yn ). Let P (a, b), for a and b nonnegative integers, be the number of paths that start at (0, 0) and end at (a, b). Find: 10 X P (i, 10 − i). i=0

14

MC40C Chapter 3.

Path Counting & Bijections

5. (AMC12-2004-B25) Given that 22004 is a 604-digit number whose first digit is 1, how many elements of the set S = {20 , 21 , 22 , . . . , 22003 } have a first digit of 4? (A) 194

(B) 195

(C) 196

(D) 197

(E) 198

6. (HMMT Feb-2006-Combinatorics-3) A moth starts at vertex A of a certain cube and is trying to get to vertex B, which is opposite A, in five or fewer “steps”, where a step consists in traveling along an edge from one vertex to another. The moth will stop as soon as it reaches B. How many ways can the moth achieve its objective?

15

Chapter 4

Stars and Bars 4.1

Notes

Stars and bars (also called sticks and stones, balls and boxes, etc.) is a counting technique which utilizes bijections. The basic problem stars and bars is: how many ways can we distribute n identical objects to k people? The idea is that we can place the n objects (“stars”) in a row, and simply count the number of ways to place k − 1 dividers (“bars”) among them. This technique is best illustrated through a simple example. Example 4.1.1. How many ways can we distribute 8 identical pieces of candy to four people if (a) every person must receive at least one piece of candy, (b) not everyone is required to receive candy? Solution. (a) We consider the candies as “stars”: ? ? ? ? ? ? ?? Since everyone must receive at least one piece of candy, we consider the seven gaps in between consecutive pieces of candy, and insert three “bars” (dividers) among them. For instance, the following solution ?| ? ? ? | ? ?| ? ? indicates that person 1 receives 1 piece of candy, person 2 receives 3 pieces, person 3 receives 2 pieces, and person 4 receives 2 pieces. There are seven gaps, of which we choose three of them to insert the bars. The number of ways is 73 = 35 . (b) Here, we allow dividers with no stars (candies) in between. We observe that any arrangement of 8 stars and 3 bars gives a unique solution. Hence the number of ways is   11 = 165 . 3 16

MC40C Chapter 4.

Stars and Bars

We may generalize the above arguments to obtain the following: Theorem 4.1.2 (Stars and bars). The following hold: ˆ The number of positive integer solutions (x1 , . . . , xk ) to the equation x1 + x2 + . . . + xk = n is n−1 k−1 . ˆ The number of non-negative integer solutions (x1 , . . . , xk ) to the equation x1 + x2 +  n+k−1 . . . + xk = n is k−1 .

Example 4.1.3. How many positive integer solutions (x1 , x2 , x3 , x4 ) satisfy the inequality x1 + x2 + x3 + x4 ≤ 12? Solution. We will add a “dummy” non-negative variable s := 12 − x1 − x2 − x3 − x4 . Then the answer simply equals the number of integer solutions to x1 + x2 + x3 + x4 + s = 12 where s ≥ 0 and xi ≥ 1. Let x0i = xi − 1, so that we equivalently seek the number of 0 0 0 0 non-negative  solutions to x1 + x2 + x3 + x4 + s = 8. Using stars and bars, the answer is  12 8+4 = 4 = 495 . 4 Example 4.1.4. (HMMT 2014 Combinatorics/5) Eli, Joy, Paul, and Sam want to form a company; the company will have 16 shares to split among the 4 people. The following constraints are imposed: ˆ Every person must get a positive integer number of shares, and all 16 shares must be given out. ˆ No one person can have more shares than the other three people combined. Assuming that shares are indistinguishable, but people are distinguishable, in how many ways can the shares be given out?

Solution. We are looking for the number of positive integer solutions to x1 + x2 + x3 + x4 = 16, subject to the constraint that the largest one is no more than the sum of the rest. Since the total sum is 16, this is equivalent to saying that xi ≤ 8 for all 1 ≤ i ≤ 4. There are 15 3 = 455 solutions to the original equation; we must subtract the bad cases. There are 4 equivalent ways to choose who  hasmore than 8 shares.  Then  3, 4, 5, 6, or 7 shares are left to the other 3. There are 22 + 32 + 42 + 52 + 62 = 73 = 35 ways for this to happen, so the answer is 455 − 4 · 35 = 315 . Example 4.1.5. (2011 AIME II/7) Ed has five identical green marbles and a large supply of identical red marbles. He arranges the green marbles and some of the red marbles in a row and finds that the number of marbles whose right hand neighbor is the same color as themselves equals the number of marbles whose right hand neighbor is the other color. An example of such an arrangement is GGRRRGGRG. let m be the maximum number of red marbles for which Ed can make such an arrangement, and let N be the number of ways in which Ed can arrange the m + 5 marbles to satisfy the requirement. Find the remainder when N is divided by 1000. 17

MC40C Chapter 4.

Stars and Bars

Solution. There are at most 10 marbles for which the right hand neighbor is a different color; 5 green and 5 where the right hand neighbor is green. Then there are at most 11 other red marbles (since the rightmost one doesn’t have a right neighbor), so m = 5 + 11 = 16. Setting  the red marbles down, there are 15 slots to place the 5 green marbles, for an answer of 15 5 = 3003 ≡ 3 (mod 1000).

4.2

Examples

1. (Folklore) How many nonnegative solutions (x1 , . . . , xm ) are there to x1 +· · ·+xm ≤ n, in terms of m and n? 2. (Andrew Kwon) Find the number of subsets of the set {1, 2, ..., 15} which have 5 elements so that no two numbers in the subset are consecutive. 3. (BMT-2016-Team-8) How many ways are there to divide 10 candies between 3 Berkeley students and 4 Stanford students, if each Berkeley student must get at least one candy? All students are distinguishable from each other; all candies are indistinguishable. 4. (Folklore) Use the Stars and Stripes argument to expand

1 (1−x)k

for arbitrary k.

5. (AMC12-2006-A25) How many non-empty subsets S of {1, 2, 3, . . . , 15} have the following two properties? (1) No two consecutive integers belong to S. (2) If S contains k elements, then S contains no number less than k. (A) 277

(B) 311

(C) 376

(D) 377

(E) 405

6. (AMC12-2010-A25) Two quadrilaterals are considered the same if one can be obtained from the other by a rotation and a translation. How many different convex cyclic quadrilaterals are there with integer sides and perimeter equal to 32? (A) 560

4.3

(B) 564

(C) 568

(D) 1498

(E) 2255

Exercises

1. (Christopher Shao) How many solutions to a + b + c + d + e = 10 in nonnegative integers have at least two of the variables as 0? 2. (AIME-2000-II-5) Given eight distinguishable rings, let n be the number of possible five-ring arrangements on the four fingers (not the thumb) of one hand. The order of rings on each finger is significant, but it is not required that each finger have a ring. Find the leftmost three nonzero digits of n. 18

MC40C Chapter 4.

Stars and Bars

3. (BMT-2016-Discrete-5) What are the last two digits of 98

.2 ..

?

4. (SMT-2018-General-14) Harrison the astronaut is trying to navigate his way through a rectangular grid in outer space. He starts at (0, 0) and needs to reach the Earth at position (6, 6). Harrison can only move upwards or rightwards. Unfortunately, there are two black holes, which are unit squares, with lower left corners at (1, 4) and (3, 1). If Harrison steps onto any corner of a black hole, he gets sucked in and won’t be able to return home. How many paths can Harrison take to get back to Earth safely? 5. (PUMaC-2014-Team-5) How many sets of positive integers (a, b, c) satisfies a > b > c > 0 and a + b + c = 103? 6. (AIME-2016-II-8) Find the number of sets {a, b, c} of three distinct positive integers with the property that the product of a, b, and c is equal to the product of 11, 21, 31, 41, 51, and 61.

19

Chapter 5

Binomial 5.1

Notes

Theorem 5.1.1 (Binomial theorem). For positive integer n, we have the following:       n n−1 n n−2 2 n n n (x + y) = x + x y+ x y + ... + xy n−1 + y n 1 2 n−1 n   X n n−i i = x y. i i=1   n n! The terms = are called binomial coefficients. They satisfy a number k k!(n − k)! of combinatorial identities you should be familiar with: Example 5.1.2 (Folklore).         n n n n + + + ... + = 2n 0 1 2 n and

      n n n n − + · · · + (−1) = 0. 0 1 n

Proof. Use the Binomial theorem on (1 + 1)n = 2n and (1 − 1)n = 0. Example 5.1.3 (Pascal’s Triangle). For positive integer n and 0 ≤ k ≤ n − 1 we have       n n n+1 + = k k+1 k+1 Proof. Say Bob is in a group with n other people  and we want to count the number of ways n+1 to pick k + 1 of them. This number is k+1 , and dividing it into the two cases whether   n Bob is in the group or not, we get that it is also equal to nk + k+1 . 20

MC40C Chapter 5.

Binomial

Example 5.1.4 (Hockey Stick Identity). For 0 ≤ k ≤ n, the following holds:           k k+1 k+2 n n+1 + + + ... + = k k k k k+1 Proof. Say we are choosing a committee of k + 1 people from a total of n + 1 people. Line the n + 1 people up. Then by doing casework on which person is the first to be chosen, we obtain the left-hand side. Example 5.1.5 (Vandermonde’s Identity). For non-negative integers m, n, r, the following holds:    r   X m n m+n = k r−k r k=0

Proof. Suppose we have m boys and  n girls, and wish to form a committee of r people. m+n The number of committees is r . Alternatively, we can choose k boys and r − k girls, where k ranges from 0 to r. Another important way in which binomial coefficients are used is the roots of unity filter. By plugging in roots of unityP into the  appropriate polynomials, we can obtain closed form expressions for sums such as k|i ni for some fixed k. Theorem 5.1.6 (Roots of unity filter). Let f (x) = X n|i

ai xi =

P

i ai x

i

and ω = e2πi/n . Then

f (x) + f (ωx) + · · · + f (ω n−1 x) . n

Proof. Collect like terms on the RHS. For every exponent divisible by n, we get ai xi for every term onPthe RHS, as desired. For every other exponent that is equal to k (mod n), we have ai xi nj=1 ω kj = 0, as desired. Thus all the coefficients on the LHS and RHS are the same. Setting f (x) = (1+x)n allows us to calculate the sums of binomial coefficients mentioned earlier. Example 5.1.7. How many subsets of {1, 2, 3, . . . , 12} are there whose sum of elements is divisible by 3? (the sum of elements of ∅ is defined to be 0) Solution. There are four elements congruent to 0 (mod 3), four elements congruent to 1 (mod 3), and four elements congruent to 2 (mod 3). Consider the polynomial f (x) = (1 + 1)4 (1 + x)4 (1 + x2 )4 = a12 x12 + . . . + a1 x + a0 . We can see that the coefficient of xk represents the number of subsets whose sum equals k. Hence, we are looking for the sum a12 + a9 + a6 + a3 + a0 . 21

MC40C Chapter 5.

Binomial

Using the roots of unity filter with ω = e2πi/3 and x = 1, we obtain: f (1) + f (ω) + f (ω 2 ) 3 212 + 16 + 16 = 3 = 1376

a12 + a9 + a6 + a3 + a0 =

Example 5.1.8. (1986 AIME/11) The polynomial 1 − x + x2 − x3 + · · · + x16 − x17 may be written in the form a0 + a1 y + a2 y 2 + · · · + a16 y 16 + a17 y 17 , where y = x + 1 and the ai ’s are constants. Find the value of a2 . Solution. We want to put the polynomial in terms of y = x + 1, so using the substitution 1 − (1 − y)18 x = y − 1, we get 1 − (y − 1) + (y − 1)2 − · · · − (y − 1)17 = by geometric series. y  Then the answer is 18 3 = 816 .

5.2

Examples

1. (A-Star) Evaluate (in terms of n) 1 · 2 · 3 · 4 + 2 · 3 · 4 · 5 + · · · + n(n + 1)(n + 2)(n + 3).

2. (Folklore) Compute

−2 n



for any natural number n and use that to expand

1 . (1−x)2

3. (Folklore) Prove the identity b n−1 c 2

1

 n 5k = fn , 2k + 1

X

2n−1

k=0

where fn is the nth Fibonacci number. 4. (CHMMC-2014-Team-9) There is a long-standing conjecture that there is no number with 2n + 1 instances in Pascal’s triangle for n ≥ 2. Assuming this is true, for how many n ≤ 100000 are there exactly 3 instances of n in Pascal’s triangle? 5. (PUMaC-2008-Combinatorics-3) Evaluate   m  2009 XX 2009 m . m n m=0 n=0

22

MC40C Chapter 5.

Binomial

6. (AMC12-2006-A24) The expression (x + y + z)2006 + (x − y − z)2006 is simplified by expanding it and combining like terms. How many terms are in the simplified expression? (A) 6018

5.3

(B) 671,676

(C) 1,007,514

(D) 1,008,016

(E) 2,015,028

Exercises

1. (A-Star) Find the last three digits of 1992 . 2. (A-Star) What is the coefficient of x5 , in the expansion of (1 − 12x5 )21 (1 + x)10 .

3. (AIME-2000-II-7) Given that 1 1 1 1 1 1 1 1 N + + + + + + + = 2!17! 3!16! 4!15! 5!14! 6!13! 7!12! 8!11! 9!10! 1!18! find the greatest integer that is less than

N 100 .

4. (AIME-2002-I-7) The Binomial Expansion is valid for exponents that are not integers. That is, for all real numbers x, y, and r with |x| > |y|, (x + y)r = xr + rxr−1 y +

r(r − 1) r−2 2 r(r − 1)(r − 2) r−3 3 x y + x y + ··· 2! 3!

What are the first three digits to the right of the decimal point in the decimal representation of (102002 + 1)10/7 ? 5. (HMMT Feb-2014-Algebra-5) Find the sum of all real numbers x such that 5x4 − 10x3 + 10x2 − 5x − 11 = 0. 6. (PUMaC-2008-Combinatorics-4) Find the sum of the values of x for which         x x x x − + − ··· + = 0. 0 1 2 2008

23

Chapter 6

Counting with Recursion 6.1

Notes

Counting by recursion is the process of counting the number of ways to do something by setting up a recurrence relation. Here is a very simple example: Example 6.1.1. How many ways can I climb up a flight of 10 stairs if I can only climb up 1 or 3 stairs at a time? Solution. Let an denote the number of ways to climb n stairs by climbing 1 or 3 stairs at a time. We have a1 = 1, a2 = 1, a3 = 2, and an = an−1 + an−3 for n ≥ 4. Computing a4 , a5 , . . . yields a10 = 28 . If the recurrence is linear, then the exact formula can be found using the roots of the characteristic polynomial. This method is explained in more detail in the Algebra chapters. If the recurrence is not linear, you can either compute the terms manually, or try to find a closed formula for the nth term. Remark 6.1.1. If you have taken a computer science or algorithms course, you may have heard the phrase dynamic programming, which is a technique of computing something recursively by cleverly storing the solutions to any computed subproblems. Example 6.1.2. (2006 AIME I/11) A collection of 8 cubes consists of one cube with edgelength k for each integer k, 1 ≤ k ≤ 8. A tower is to be built using all 8 cubes according to the rules: ˆ Any cube may be the bottom cube in the tower. ˆ The cube immediately on top of a cube with edge-length k must have edge-length at most k + 2.

24

MC40C Chapter 6.

Counting with Recursion

Let T be the number of different towers than can be constructed. What is the remainder when T is divided by 1000? Solution. Let’s find a recursion for T based on the number of cubes. Say there are k different towers when there are n cubes, for n ≥ 2. Then for n + 1 cubes, note that the largest cube can be on the bottom, or go right on top of the nth or (n − 1)th largest cubes. If it’s taken away then we get the towers of size n. Thus there are 3k towers. Since there are 2 towers when n = 2, we have T = 2 · 36 = 1458 ⇒ 458 . Example 6.1.3. (2003 AIME II/13) A bug starts at a vertex of an equilateral triangle. On each move, it randomly selects one of the two vertices where it is not currently located, and crawls along a side of the triangle to that vertex. Given that the probability that the bug moves to its starting vertex on its tenth move is m/n, where m and n are relatively prime positive integers, find m + n. Solution. There are 1024 total sequences; let’s count the number of ways to end up at the starting vertex. The number of ways to end up at each of the other two vertices is always the same by symmetry, so let this number be ni after i moves. Then we are looking for 210 − n10 ; let’s see what recurrence we get. The number of ways to get to any vertex after i + 1 moves is simply the sum of the number of ways to get to the other two after i moves, so ni+1 = ni + 2i − 2ni = 2i − ni . At this point we could multiply this equation by two and cancel the power of 2 to get a linear recurrence, but these numbers are small enough that it’s easy to straight up calculate the entire sequence, giving n10 = 341. Then the desired 342 171 probability is = ⇒ 683 . 1024 512

6.2

Examples

1. (Folklore) How many ways are there to tile a 2 by n grid with only 1 by 2 dominoes? 2. (HMMT Feb-2002-Guts-13) A domino is a 1-by-2 or 2-by-1 rectangle. A domino tiling of a region of the plane is a way of covering it (and only it) completely by nonoverlapping dominoes. For instance, there is one domino tiling of a 2-by-1 rectangle and there are 2 tilings of a 2-by-2 rectangle (one consisting of two horizontal dominoes and one consisting of two vertical dominoes). How many domino tilings are there of a 2-by-10 rectangle? 3. (CHMMC-2010 Winter-Tiebreaker-3) Compute the number of ways of tiling the 2 × 10 grid below with the three tiles shown. There is an infinite supply of each tile, and rotating or reflecting the tiles is not allowed.

25

MC40C Chapter 6.

Counting with Recursion

4. (HMMT Feb-2002-Guts-15) How many sequences of 0s and 1s are there of length 10 such that there are no three 0s or 1s consecutively anywhere in the sequence? 5. (CHMMC-2010 Winter-Team-10) Compute the number of 10-bit sequences of 0’s and 1’s do not contain 001 as a subsequence. 6. (PUMaC-2014-Team-6) Compute the sum of all positive integers less than 100 that do not have consecutive 1s in their binary representation.

6.3

Exercises

1. (CHMMC-2016-Individual-6) How many binary strings of length 10 are there that don’t contain either of the substrings 101 or 010? 2. (CHMMC-2012 Fall-Team-5) At each step, a rectangular tile of length 1, 2, or, 3 is chosen at random, what is the probability that the total length is 10 after 5 steps? 3. (PUMaC-2014-Combinatorics-4) Amy has a 2×10 puzzle grid which she can use 1×1 and 1 × 2 (1 vertical, 2 horizontal) tiles to cover. How many ways can she exactly cover the grid without any tiles overlapping and without rotating the tiles? 4. (HMMT Feb-2002-Guts-14) An omino is a 1-by-1 square or a 1-by-2 horizontal rectangle. An omino tiling of a region of the plane is a way of covering it (and only it) by ominoes. How many omino tilings are there of a 2-by-10 horizontal rectangle? 5. (HMMT Feb-2008-Guts-8) Trodgor the dragon is burning down a village consisting of 90 cottages. At time t = 0 an angry peasant arises from each cottage, and every 8 minutes (480 seconds) thereafter another angry peasant spontaneously generates from each non-burned cottage. It takes Trodgor 5 seconds to either burn a peasant or to burn a cottage, but Trodgor cannot begin burning cottages until all the peasants around him have been burned. How many seconds does it take Trodgor to burn down the entire village? 6. (AMC12-2012-A22) Distinct planes p1 , p2 , . . . , pk S intersect the interior of a cube Q. Let S be the union of the faces of Q and let P = kj=1 pj . The intersection of P and S consists of the union of all segments joining the midpoints of every pair of edges belonging to the same face of Q. What is the difference between the maximum and minimum possible values of k? 26

MC40C Chapter 6.

(A) 8

(B) 12

Counting with Recursion

(C) 20

(D) 23

27

(E) 24

Chapter 7

Probability 7.1

Notes

Probability is a measure of the likelihood of an event occurring. The probability of an event is a real number in the interval [0, 1] where an event with probability 0 (almost) never happens1 , while an event with probability 1 is (almost) certain to happen. The probability of event A is denoted P (A); some texts use p(A) or Pr(A). In probability theory, we use random variables to indicate variables whose value is random and according to some probability distribution. For instance, we may let X be a random variable which represents the number obtained after rolling a six-sided die. Then P (X = 1) = P (X = 2) = . . . = P (X = 6) = 16 .

7.2

Basic properties, definitions

We give some basic but important facts: ˆ For any event A, P (A) ∈ [0, 1]. ˆ For any event A, P (A) = 1 − P (A). Here A denotes the complement of A, or the event that A does not occur. (This is useful on probability problems where the complement may be easier to compute.) ˆ For any events A and B, P (A ∪ B) = P (A) + P (B) − P (A ∩ B). A corollary of this fact is that P (A ∪ B) ≤ P (A) + P (B); this is called the union bound. ˆ Events A and B are disjoint if A and B cannot simultaneously occur. For disjoint events A and B, P (A ∩ B) = 0 and P (A ∪ B) = P (A) + P (B). 1 The word “almost” is necessarily; consider choosing a random real number x in [0, 1]. The probability that x is rational is zero, though it is possible that x is rational.

28

MC40C Chapter 7.

Probability

ˆ Events A and B are independent if the fact whether A occurred does not influence the likelihood of B occurring. If A and B are independent, then P (A ∩ B) = P (A)P (B).

We give a useful fact which relies on independence and disjoint events. Theorem 7.2.1. Suppose one flips n coins, where each coin has probability p of landing heads, independent  of other flips. Then for 0 ≤ k ≤ n, the probability that exactly k coins land heads is nk pk (1 − p)n−k . Example 7.2.2. (2009 AIME I/3) A coin that comes up heads with probability p > 0 and tails with probability 1 − p > 0 independently on each flip is flipped eight times. Suppose 1 the probability of three heads and five tails is equal to 25 of the probability of five heads m and three tails. Let p = n , where m and n are relatively prime positive integers. Find m + n.     1 · 85 p5 (1 − p)3 . As 83 = 85 , we Solution. Using the above fact, we have 83 p3 (1 − p)5 = 25  1 2 can divide both sides by 83 p3 (1 − p)3 in order to obtain (1 − p)2 = 25 p . As both sides are 1 5 positive, taking the square root yields 1 − p = 5 p =⇒ p = 6 , so m + n = 5 + 6 = 11 . Example 7.2.3. (2010 AIME I/4) Jackie and Phil have two fair coins and a third coin that comes up heads with probability 74 . Jackie flips the three coins, and then Phil flips the three coins. Let m n be the probability that Jackie gets the same number of heads as Phil, where m and n are relatively prime positive integers. Find m + n. 3 5 Solution. The probability of 0 heads is 28 , 1 head is 37 · 12 + 47 · 14 = 14 , 3 heads is 17 , and so 11 the probability of 2 heads is 28 . The desired probability is simply the sum of the squares of these probabilities, which is 123 392 ⇒ 515 .

7.3

Conditional probability and Bayes’ theorem

The conditional probability of A, given that B occurred, is denoted P (A|B) and P (A ∩ B) . Clearly, if A and B are independent events, then is defined as P (A|B) = P (B) P (A|B) = P (B). The following theorem follows immediately from the definitions, but is still crucially important in fields related to statistics. Theorem 7.3.1 (Bayes’ Theorem). P (A|B) =

P (B|A)P (A) P (B)

In practice, Bayes’ theorem is used as a formalization of how one should update probability models: if P (A) represents a prior belief in event A, then P (A|B) represents the updated, posterior belief based on event B occurring. We solved the following problem in the recursion chapter, but here is a slicker solution. 29

MC40C Chapter 7.

Probability

Example 7.3.2. (2003 AIME II/13) A bug starts at a vertex of an equilateral triangle. On each move, it randomly selects one of the two vertices where it is not currently located, and crawls along a side of the triangle to that vertex. Given that the probability that the bug moves to its starting vertex on its tenth move is m/n, where m and n are relatively prime positive integers, find m + n. Solution. Each move is either clockwise or counterclockwise. If the bug makes c clockwise moves, then it ends up 10 − 2c turns clockwise from its original position. This needs to be a multiple of 3 for the bug to return to its starting position, which means c = 2, 5, or 8. 10 10 + 10 171 5 + 8 This gives a probability of 2 = ⇒ 683 . 10 2 512

7.4

Examples

1. (AIME-2000-I-5) Each of two boxes contains both black and white marbles, and the total number of marbles in the two boxes is 25. One marble is taken out of each box 27 randomly. The probability that both marbles are black is 50 , and the probability that m both marbles are white is n , where m and n are relatively prime positive integers. What is m + n? 2. (HMMT Feb-2004-Combinatorics-4) Andrea flips a fair coin repeatedly, continuing until she either flips two heads in a row (the sequence HH) or flips tails followed by heads (the sequence TH). What is the probability that she will stop after flipping HH? 3. (AMC12-2018-A24) Alice, Bob, and Carol play a game in which each of them chooses a real number between 0 and 1. The winner of the game is the one whose number is between the numbers chosen by the other two players. Alice announces that she will choose her number uniformly at random from all the numbers between 0 and 1, and Bob announces that he will choose his number uniformly at random from all the numbers between 12 and 32 . Armed with this information, what number should Carol choose to maximize her chance of winning? (A)

1 2

(B)

13 24

(C)

7 12

(D)

5 8

(E)

2 3

4. (HMMT Feb-2002-Advanced Topics-1) Eight knights are randomly placed on a chessboard (not necessarily on distinct squares). A knight on a given square attacks all the squares that can be reached by moving either (1) two squares up or down followed by one squares left or right, or (2) two squares left or right followed by one square up or down. Find the probability that every square, occupied or not, is attacked by some knight.

30

MC40C Chapter 7.

Probability

5. (PUMaC-2010-Combinatorics-1) PUMaCDonalds, a newly-opened fast food restaurant, has 5 menu items. If the first 4 customers each choose one menu item at random, the probability that the 4th customer orders a previously unordered item is m/n, where m and n are relatively prime positive integers. Find m + n. 6. (AIME-2008-I-9) Ten identical crates each have dimensions 3 ft × 4 ft × 6 ft. The first crate is placed flat on the floor. Each of the remaining nine crates is placed, in turn, flat on top of the previous crate, and the orientation of each crate is chosen at random. Let m n be the probability that the stack of crates is exactly 41 ft tall, where m and n are relatively prime positive integers. Find m.

7.5

Exercises

1. (HMMT Feb-2004-Combinatorics-5) A best-of-9 series is to be played between two teams; that is, the first team to win 5 games is the winner. The Mathletes have a 2 chance of of winning any given game. What is the probability that exactly 7 games 3 will need to be played to determine a winner? 2. (AIME-2010-I-4) Jackie and Phil have two fair coins and a third coin that comes up heads with probability 74 . Jackie flips the three coins, and then Phil flips the three coins. Let m n be the probability that Jackie gets the same number of heads as Phil, where m and n are relatively prime positive integers. Find m + n. 3. (AIME-2014-II-6) Charles has two six-sided dice. One of the die is fair, and the other die is biased so that it comes up six with probability 32 and each of the other five 1 sides has probability 15 . Charles chooses one of the two dice at random and rolls it three times. Given that the first two rolls are both sixes, the probability that the third roll will also be a six is pq , where p and q are relatively prime positive integers. Find p + q. 4. (CHMMC-2016-Individual-5) Suppose you have 27 identical unit cubes, where on each cube the three faces adjacent to one vertex are colored red, and the three faces adjacent to the opposite vertex are colored blue. The cubes are assembled randomly into a single 3 by 3 by 3 cube. (In particular, the orientation of each unit cube is distributed uniformly over the possible orientations.) The probability that the 1 outside of this cube is entirely a single color is equal to n . Find n. 2 5. (HMMT Feb-2010-Guts-16) Jessica has three marbles colored red, green, and blue. She randomly selects a non-empty subset of them (such that each subset is equally likely) and puts them in a bag. You then draw three marbles from the bag with replacement. The colors you see are red, blue, red. What is the probability that the only marbles in the bag are red and blue? 31

MC40C Chapter 7.

Probability

6. (AMC12-2012-A23) Let S be the square one of whose diagonals has endpoints (0.1, 0.7) and (−0.1, −0.7). A point v = (x, y) is chosen uniformly at random over all pairs of real numbers x and y such that 0 ≤ x ≤ 2012 and 0 ≤ y ≤ 2012. Let T (v) be a translated copy of S centered at v. What is the probability that the square region determined by T (v) contains exactly two points with integer coefficients in its interior? (A) 0.125

(B) 0.14

(C) 0.16

(D) 0.25

32

(E) 0.32

Chapter 8

Expected Value 8.1

Notes

Let X be a random variable. The expected value of X, typically denoted E(X) or E(X), is a probability-weighted average over all possible values X can take on, where the weights equal their corresponding probabilities. The expected value of X is also sometimes called the mean of X. We formalize the notion of expected value below. Definition 8.1.1 (Expected value with finite sample space). Let X be a random P variable which takes on P values x1 , x2 , . . . , xn with probabilities p1 , p2 , . . . , pn such that ni=1 pi = 1. Then E(X) = ni=1 pi xi . For instance, if X represents the value obtained by rolling a fair six-sided die, then E(X) = 61 × 1 + 61 × 2 + . . . + 16 × 6 = 3.5. R∞ More generally, if X is a real-valued random variable, then E(X) = −∞ xf (x) dx, where f (x) is called the probability density function corresponding to X.

8.2

Linearity of expectation

Linearity of expectation is an extremely powerful concept, which essentially states that expected values are additive. Theorem 8.2.1 (Linearity of expectation). For any random variables X, Y , we have E[X + Y ] = E[X] + E[Y ], even if they are dependent. P  P k More generally, for any random variables X1 , . . . , Xk , E X = ki=1 E(Xi ). i i=1 Furthermore, E[cX] = cE[X] for any constant c.

33

MC40C Chapter 8.

8.3

Expected Value

Variance

Variance is a measure of how “spread out” a set of numbers is with respect to its mean. In the context of random variables, the variance of X is defined to be the expected squared distance from X’s mean. Definition 8.3.1 (Variance). Let X be a random variable. Then the variance of X is defined as Var(X) = E[(X − E(X))2 ]. Recall the expected value of a random variable is also often called its mean. We usually use µ and σ 2 to denote the mean and variance of a random variable X, respectively. We will be able to prove some basic properties about variance. Theorem 8.3.2 (Variance of a 0-1 random variable). Let X be a random variable which takes value 1 with probability p and 0 with probability 1 − p. Then Var(X) = p(1 − p). Proof. We have E(X) = p. Using the definition of variance, (X − E(X))2 equals (1 − p)2 with probability p, and (0 − p)2 = p2 with probability 1 − p. Then by definition of expectation, E(X −E(X))2 = p(1−p)2 +(1−p)p2 = (p3 −2p2 +p)+(−p3 +p2 ) = p(1−p). Theorem 8.3.3. Let X be a random variable. Then Var(X) = E[X 2 ] − E[X]2 . Proof. Using the definition of variance, Var(X) = E[(X − E(X))2 ]. Expanding, this equals E(X 2 − 2XE(X) + E(X)2 ). By linearity of expectation: E(X 2 − 2XE(X) + E(X)2 ) = E(X 2 ) − E(2XE(X)) + E(E(X)2 ) E(X) is a constant given X, so E(2XE(X)) = E(X)E(2X) and E(E(X)2 ) = E(X)2 : = E(X 2 ) − E(X)E(2X) + E(X)2 = E(X 2 ) − 2E(X)E(X) + E(X)2 = E(X 2 ) − E(X)2

Theorem 8.3.4. The following facts about variance hold: ˆ If c is a constant, then Var(cX) = c2 Var(X). ˆ If X and Y are independent, then Var(X + Y ) = Var(X) + Var(Y ).

We can generalize the above theorem to show that Var(aX + bY ) = a2 Var(X) + b2 Var(Y ) + 2ab(E[XY ] − E[X]E[Y ]). The value E[XY ] − E[X]E[Y ] is known as the covariance between X and Y . Note that Cov(X, X) = Var(X) and Cov(X, Y ) = 0 when X and Y are independent (the converse is not true). Using linearity of expectation, it is easy to see that Cov(X, Y ) = E[(X − E[X])(Y − E[Y ])], further demonstrating how this generalizes variance. 34

MC40C Chapter 8.

Expected Value

Example 8.3.5. (HMMT) In an election, there are 100 voters and 5 candidates. If each voter votes randomly among the 5 candidates, what is the expected number of candidates who receive at least one vote? Solution. The probability that each individual candidate receives at least one vote is 1 − ( 45 )100 . This means that if Xi is the (indicator) random variable which equals 1 if candidate i receives at least one vote and 0 otherwise, then E[Xi ] = 1 − ( 54 )100 . We are looking for  100 ! 4 E[X1 + · · · + X5 ], which by linearity of expectation is simply 5 1 − . 5 Example 8.3.6. (2006 AIME I/6) Let S be the set of real numbers that can be represented as repeating decimals of the form 0.abc where a, b, c are distinct digits. Find the sum of the elements of S. Solution. The average value of each of a, b, c is 4.5 over all possibilities. Since 0.abc = 100a + 10b + c 450 + 45 + 4.5 , the sum of all 720 elements of S is 720 · = 360 . 999 999

8.4

Examples

1. (Brice Huang) In a party with 20 people, each pair of people are friends with probability 12 and enemies with probability 12 . What is the expected number of sets of 3 people who are either all friends with one another or all enemies with one another? 2. (HMMT Feb-2014-Guts-2) Let x1 , x2 , . . . , x100 be defined so that for each i, xi is a (uniformly) random integer between 1 and 6 inclusive. Find the expected number of integers in the set {x1 , x1 + x2 , . . . , x1 + x2 + · · · + x100 } that are multiples of 6. 3. (CHMMC-2016-Individual-3) A gambler offers you a $2 ticket to play the following game. First, you pick a real number 0 ≤ p ≤ 1. Then, you are given a weighted coin with probability p of coming up heads and probability 1 − p of coming up tails, and flip this coin twice. The first time the coin comes up heads, you receive $1, and the first time it comes up tails, you receive $2. Given an optimal choice of p, what is your expected net winning? 4. (HMMT Feb-2010-Guts-10) Let ABC be a triangle with AB = 8, BC = 15, and AC = 17. Point X is chosen at random on line segment AB. Point Y is chosen at random on line segment BC. Point Z is chosen at random on line segment CA. What is the expected area of triangle XY Z? 5. (PUMaC-2014-Team-10) A gambler has $25 and each turn, if the gambler has a positive amount of money, a fair coin is flipped and if it is heads, the gambler gains a dollar and if it is tails, the gambler loses a dollar. But if the gambler has no money, he 35

MC40C Chapter 8.

Expected Value

will automatically be given a dollar (which counts as a turn). What is the expected number of turns for the gambler to double his money? 6. (PUMaC-2014-Team-8) Alice has 100 balls and 10 buckets. She takes each ball and puts it in a bucket that she chooses at random. After she is done, let bi be the P number 2 of balls in the ith bucket, for 1 ≤ i ≤ 10. Compute the expected value of 10 i=1 bi .

8.5

Exercises

1. (BMT-2012-Tournament-Round5-P5) Let a1 , a2 , ..., an be a sequence of real numbers. Call a k-inversion (0 < k ≤ n) of a sequence to be indices i1 , i2 , ..., ik such that i1 < i2 < ... < ik but ai1 > ai2 > aik . Calculate the expected number of 6-inversions in a random permutation of the set {1, 2, ..., 10}. 2. (Lazar Ilic) Start with 1 and flip a coin. If heads add 1 to your number if tails add 2. What is the expected value of the number of flips until your number is a multiple of 5? Express your answer as a common fraction in reduced form. 3. (BMT-2012-Tournament-Round2-P1) 4 balls are distributed uniformly at random among 6 bins. What is the expected number of empty bins? 4. (HMMT Feb-2010-Guts-9) Indecisive Andy starts out at the midpoint of the 1-unitlong segment HT . He flips 2010 coins. On each flip, if the coin is heads, he moves halfway towards endpoint H, and if the coin is tails, he moves halfway towards endpoint T . After his 2010 moves, what is the expected distance between Andy and the midpoint of HT ? Express your answer in decimals. 5. (BMT-2012-Tournament-Round6-P2) Katniss has an n sided fair die which she rolls. If n > 2, she can either choose to let the value rolled be her score, or she can choose to roll an n − 1 sided fair die, continuing the process. What is the expected value of her score assuming Katniss starts with a 6-sided die and plays to maximize this expected value? 6. (PUMaC-2016-Combinatorics-4) A knight is placed at the origin of the Cartesian plane. Each turn, the knight moves in an chess L-shape (2 units parallel to one axis and 1 unit parallel to the other) to one of eight possible locations, chosen at random. After 2016 such turns, what is the expected value of the square of the distance of the knight from the origin?

36

Chapter 9

Markov Chains 9.1

Notes

A Markov chain is a model which attempts to describe a random variable X which takes on one or more “states”, where the probability of each state in the sequence depends only on the previous state. We can represent a Markov chain using a directed graph (state diagram), where the vertices represent individual “states,” and directed edges indicate the probability of transitioning from one state to the other. For example, suppose that in a certain land, every day is either rainy or sunny. Further, suppose that if today is rainy, then tomorrow is rainy with probability 0.6 and sunny with probability 0.4. If today is sunny, then tomorrow is rainy with probability 0.1 and sunny with probability 0.9. The following 2-state Markov chain describes this scenario: 0.6

0.9 0.1

Rain

Sun 0.4

After many days, the variable X (rain or sun) approaches a “steady state” in which it is at rainy with some probability p, and sunny with probability 1 − p. Finding these probabilities is easy, as we know that they must remain invariant after transition. So to calculate p, we set up an equation: p = 0.6p + (0.1)(1 − p) ⇒ p = 0.2. So approximately 20% of days are rainy. In practice, the principle behind Markov chains is used in probability questions by isolating what probabilities don’t change. For example, say we are flipping coins until we get 5 heads in a row. The expected number of more coins we’ll need to flip after a the sequence HHHHT and after the sequence T T T T T are the same. In fact, only the number 37

MC40C Chapter 9.

Markov Chains

of heads in our current streak matters. We can use this principle to divide the probability space into different events and relate them recurseively. Example 9.1.1. (2009 AIME II/8) Dave rolls a fair six-sided die until a six appears for the first time. Independently, Linda rolls a fair six-sided die until a six appears for the first time. Let m and n be relatively prime positive integers such that m n is the probability that the number of times Dave rolls his die is equal to or within one of the number of times Linda rolls her die. Find m + n.  n−1   1 Solution. Let the probability it takes n rolls be pn ; then pn = 65 Then the 6 desired probability is p1 (p1 + p2 ) + p2 (p1 + p2 + p3 ) + · · · ; note that after the first term, 25 this forms a geometric sequence with common ratio 36 . Thus the answer is equal to 8 36 ⇒ 41 . p1 (p1 + p2 ) + 11 p2 (p1 + p2 + p3 ), which we calculate to be 33 Example 9.1.2. (HMMT 2012) You are repeatedly flipping a fair coin. What is the expected number of flips until the first time that your previous 2012 flips are ‘HTHT...HT’ ? Solution. Note that every binary string of fixed length has the same probability of appearing in that same number of flips. Let s = ‘HT . . . HT 0 . Now let f (n) be the number of strings of length n which don’t contain s., and let g(n) be the number which first contain it on their nth character. Now if we append the s to every string in f (n), we get the strings in g(n + 2), g(n + 4), . . . , g(n + 2012). P∞ Say we take t flips. Note that E[t] = n=0 P (t > n). We can use our previous relation to calculate this sum. Indeed, since f (n) = 2n P (t > n), we get P (t > n) = 22 P (t = n + 2) + 24 P (t = n + 4) + · · · + 22012 P (t = n + 2012). Summing over all values of n, we see that each of the probabilities on the right hand side add to 1, so we get 22014 − 4 E(t) = 22 + 24 + · · · + 22012 = . 3

9.2

Examples

1. (HMMT Feb-2002-Advanced Topics-4) Two fair coins are simultaneously flipped. This is done repeatedly until at least one of the coins comes up heads, at which point the process stops. What is the probability that the other coin also came up heads on this last flip? 2. (AIME-2019-I-5) A moving particle starts at the point (4, 4) and moves until it hits one of the coordinate axes for the first time. When the particle is at the point (a, b), it moves at random to one of the points (a − 1, b), (a, b − 1), or (a − 1, b − 1), each with probability 13 , independently of its previous moves. The probability that it will hit the coordinate axes at (0, 0) is 3mn , where m and n are positive integers. Find m + n. 38

MC40C Chapter 9.

Markov Chains

3. (HMMT Feb-2016-Guts-21) Tim starts with a number n, then repeatedly flips a fair coin. If it lands heads he subtracts 1 from his number and if it lands tails he subtracts 2. Let En be the expected number of flips Tim does before his number is zero or negative. Find the pair (a, b) such that lim (En − an − b) = 0.

n→∞

4. (BMT-2012-Individual-8) You are tossing an unbiased coin. The last 28 consecutive flips have all resulted in heads. Let x be the expected number of additional tosses you must make before you get 60 consecutive heads. Find the sum of all distinct prime factors in x. 5. (BMT-2014-Individual-15) Albert and Kevin are playing a game. Kevin has a 10% chance of winning any given round in the match. If Kevin wins the first game, he wins the match. If not, he requests that the match be extended to a best of 3. If he wins the best of 3, he wins the match. If not, then he requests the match be extended to a best of 5, and so forth. What is the probability that Kevin eventually wins the match? (A best of 2n + 1 match consists of a series of rounds. The first person to reach n + 1 winning games wins the match) 6. (PUMaC-2010-Combinatorics-4) Erick stands in the square in the 2nd row and 2nd column of a 5 by 5 chessboard. There are $1 bills in the top left and bottom right squares and there are $5 bills in the top right and bottom left squares, as shown below.

Every second, Erick randomly chooses a square adjacent to the one he currently stands in (that is, a square sharing an edge with the one he currently stands in) and moves to that square. When Erick reaches a square with money on it, he takes it and quits. The expected value of Erick’s winnings in dollars is m/n, where m and n are relatively prime positive integers. Find m + n.

9.3

Exercises

1. (HMMT Feb-2016-Combinatorics-2) Starting with an empty string, we create a string by repeatedly appending one of the letters H, M , T with probabilities 41 , 12 , 41 , 39

MC40C Chapter 9.

Markov Chains

respectively, until the letter M appears twice consecutively. What is the expected value of the length of the resulting string? 2. (Brice Huang) A circular wire has circumference 4 inches. An ant starts at some point on the wire, and each minute walks an inch clockwise or counterclockwise with equal probability. What is the expected number of minutes before the ant reaches the point diametrically across from where he began? 3. (AIME-2019-II-2) Lily pads 1, 2, 3, . . . lie in a row on a pond. A frog makes a sequence of jumps starting on pad 1. From any pad k the frog jumps to either pad k + 1 or pad k + 2 chosen randomly with probability 21 and independently of other jumps. The probability that the frog visits pad 7 is pq , where p and q are relatively prime positive integers. Find p + q. 4. (PUMaC-2016-Combinatorics-6) The George Washington Bridge is 2016 meters long. Sally is standing on the George Washington Bridge, 1010 meters from its left end. Each step, she either moves 1 meter to the left or 1 meter to the right, each with probability 21 . What is the expected number of steps she will take to reach an end of the bridge? 5. (Kevin Liu) Let A and B be opposite vertices of a cube. An ant starts at vertex A. Each minute, the ant randomly chooses one of the three vertices adjacent to its current vertex and walks to the chosen vertex. On average, how many minutes will it take the ant to reach vertex B? 6. (HMMT Nov-2017-Guts-21) A box contains three balls, each of a different color. Every minute, Randall randomly draws a ball from the box, notes its color, and then returns it to the box. Consider the following two conditions: (a) Some ball has been drawn at least three times (not necessarily consecutively). (b) Every ball has been drawn at least once. What is the probability that condition (1) is met before condition (2)?

40

Chapter 10

Geometric Counting 10.1

Notes

Sometimes a problem will ask you to count something on a 2D or 3D figure. In these cases, the geometry involved is usually fairly simple. It is useful to be able to picture the diagram and internalize it to make sure you’re using all the relevant geometric properties. Theorem 10.1.1 (Euler’s formula). For any convex polyhedron containing V vertices, E edges, and F faces, we have V − E + F = 2. (More generally, V − E + F = 2 for all planar graphs.) Example 10.1.2. (2016 AIME I/3) A regular icosahedron is a 20-faced solid where each face is an equilateral triangle and five triangles meet at every vertex. The regular icosahedron shown below has one vertex at the top, one vertex at the bottom, an upper pentagon of five vertices all adjacent to the top vertex and all in the same horizontal plane, and a lower pentagon of five vertices all adjacent to the bottom vertex and all in another horizontal plane. Find the number of paths from the top vertex to the bottom vertex such that each part of a path goes downward or horizontally along an edge of the icosahedron, and no ver-

tex is repeated. Solution. There are 5 choices for the first move, and then there are 9 choices for the moves before the path goes down again. There are 2 ways to move downward, at which point 41

MC40C Chapter 10.

Geometric Counting

there are another 9 choices to move horizontally before going down to the final vertex. Thus there are 5 · 9 · 2 · 9 = 810 paths. Example 10.1.3. (1993 AIME/10) Euler’s formula states that for a convex polyhedron with V vertices, E edges, and F faces, V − E + F = 2. A particular convex polyhedron has 32 faces, each of which is either a triangle or a pentagon. At each of its V vertices, T triangular faces and P pentagonal faces meet. What is the value of 100P + 10T + V ? Solution. By Euler’s formula, we have E = V + 30. Now every vertex corresponds to T triangles and P pentagons, but this counts each triangle three times and each pentagon VT VP five times. Thus we have + = 32. Furthermore, since there are T + P faces 3 5 surrounding each vertex, the degree of each vertex is T + P . Thus counting the edges, we have 2E = V (T +P ). Thus our equations become V (5T +3P ) = 480 and V (T +P −2) = 60. This gives V (2T + 6) = 300 ⇒ V (T + 3) = 150, so the only possibility is V = 30. This leads to T = 2 and P = 2, so the answer is 250 .

10.2

Examples

1. (HMMT Feb-2016-Combinatorics-1) For positive integers n, let Sn be the set of integers x such that n distinct lines, no three concurrent, can divide a plane into x regions (for example, S2 = {3, 4}, because the plane is divided into 3 regions if the two lines are parallel, and 4 regions otherwise). What is the minimum i such that Si contains at least 4 elements? 2. (AIME-2014-I-5) Let the set S = {P1 , P2 , . . . , P12 } consist of the twelve vertices of a regular 12-gon. A subset Q of S is called communal if there is a circle such that all points of Q are inside the circle, and all points of S not in Q are outside of the circle. How many communal subsets are there? (Note that the empty set is a communal subset.) 3. (HMMT Feb-2002-Guts-2) A lattice point in the plane is a point of the form (n, m), where n and m are integers. Consider a set S of lattice points. We construct the transform of S, denoted by S 0 , by the following rule: the pair (n, m) is in S 0 if and only if any of (n, m − 1), (n, m + 1), (n − 1, m), (n + 1, m), and (n, m) is in S. How many elements are in the set obtained by successively transforming {(0, 0)} 14 times? 4. (ARML-2014-Team-2) A point √ is selected at random from the interior of a right triangle with legs of length 2 3 and 4. Let p be the probability that the distance between the point and the nearest vertex is less than 2. Then p can be written in √ the form a + bπ, where a and b are rational numbers. Compute (a, b).

42

MC40C Chapter 10.

Geometric Counting

5. (CHMMC-2010 Fall-Team-4) Dagan has a wooden cube. He paints each of the six faces a different color. He then cuts up the cube to get eight identically-sized smaller cubes, each of which now has three painted faces and three unpainted faces. He then puts the smaller cubes back together into one larger cube such that no unpainted face is visible. Compute the number of different cubes that Dagan can make this way. Two cubes are considered the same if one can be rotated to obtain the other. You may express your answer either as an integer or as a product of prime numbers. 6. (PUMaC-2014-Combinatorics-1) What is the largest n such that a square cannot be partitioned into n smaller, nonoverlapping squares?

10.3

Exercises

1. (AIME-2002-I-5) Let A1 , A2 , . . . , A12 be the vertices of a regular dodecagon. How many distinct squares in the plane of the dodecagon have at least two vertices in the set {A1 , A2 , . . . , A12 }? 2. (AIME-2006-II-5) When rolling a certain unfair six-sided die with faces numbered 1, 2, 3, 4, 5, and 6, the probability of obtaining face F is greater than 1/6, the probability of obtaining the face opposite face F is less than 1/6, the probability of obtaining each of the other faces is 1/6, and the sum of the numbers on each pair of opposite faces is 7. When two such dice are rolled, the probability of obtaining a sum of 7 is 47/288. Given that the probability of obtaining face F is m/n, where m and n are relatively prime positive integers, find m + n. 3. (AIME-2016-II-4) An a × b × c rectangular box is built from a · b · c unit cubes. Each unit cube is colored red, green, or yellow. Each of the a layers of size 1 × b × c parallel to the (b × c) faces of the box contains exactly 9 red cubes, exactly 12 green cubes, and some yellow cubes. Each of the b layers of size a × 1 × c parallel to the (a × c) faces of the box contains exactly 20 green cubes, exactly 25 yellow cubes, and some red cubes. Find the smallest possible volume of the box. 4. (BMT-2012-Tournament-Round1-P6) A 3 dimensional cube contains “cubes” of smaller dimensions, i.e.: faces (2-cubes), edges (1-cubes), and vertices (0-cubes). How many 3-cubes are in a 5-cube? 5. (PUMaC-2010-Combinatorics-3) Sterling draws 6 circles on the plane, which divide the plane into regions (including the unbounded region). What is the maximum number of resulting regions? 6. (AIME-2018-I-7) A right hexagonal prism has height 2. The bases are regular hexagons with side length 1. Any 3 of the 12 vertices determine a triangle. Find the number of these triangles that are isosceles (including equilateral triangles). 43

Chapter 11

Generating Functions 11.1

Notes

Generating functions allow us to encode sequences of numbers using functions, and are a very powerful technique in counting. Definition 11.1.1 (Ordinary generating function). Given a sequence a0 , a1 , a2 , . . . , define 1 corresponding to the sequence {a } to be the infinite the ordinary generating n P∞function n power series G(x) = n=0 an x = a0 + a1 x + a2 x2 + a3 x3 + . . .. For now, we will ignore the issue of convergence; with generating functions, it is common 1 to apply the formula 1 + x + x2 + . . . = 1−x , even if x is not contained in the radius of convergence (i.e. |x| < 1). Here are a few useful sequences and their corresponding generating functions: 1 The word “ordinary” is used to distinguish from other types of generating functions (e.g. exponential generating functions), but from now on, we simply refer to them as “generating functions.”

44

MC40C Chapter 11.

Generating Functions

(1, 0, 0, 0, 0, . . .) ⇐⇒ 1 (1, 2, 3, 0, 0, . . .) ⇐⇒ 1 + 2x + 3x2 1 1−x x 2 3 4 (0, 1, 1, 1, 1, . . .) ⇐⇒ x + x + x + x + . . . = 1−x 1 2 4 6 (1, 0, 1, 0, 1, . . .) ⇐⇒ 1 + x + x + x + . . . = 1 − x2 (1, 1, 1, 1, 1, . . .) ⇐⇒ 1 + x + x2 + x3 + . . . =

(1, 2, 3, 4, 5, . . .) ⇐⇒ 1 + 2x + 3x2 + 4x3 + 5x4 + . . . =          ∞   X 1 i i−k k+1 k+2 k+3 k x = , , , , . . . ⇐⇒ k k k k k (1 − x)k+1

1 (1 − x)2

for all k ≥ 0

i=k

How do we derive the last two generating functions? We will see how by introducing various properties which allow us to manipulate generating functions around.

11.2

Operations on generating functions

Recall that a sequence (a0 , a1 , a2 , . . .) corresponds with the generating function G(x) = a0 + a1 x + a2 x2 + . . .. We give some operations that can be performed on generating functions: ˆ (Scaling) If (a0 , a1 , a2 , . . .) ⇐⇒ G(x), then (ca0 , ca1 , ca2 , . . .) ⇐⇒ cG(x) for all constants c. ˆ (Shifting by 1 (by k)) If (a0 , a1 , a2 , . . .) ⇐⇒ G(x), then (0, a0 , a1 , a2 , . . .) ⇐⇒ xG(x). More generally, (0, 0, . . . , 0, a0 , a1 , a2 , . . .) ⇐⇒ xk G(x). | {z } k 0’s

ˆ (Addition) If (a0 , a1 , a2 , . . .) ⇐⇒ G(x) and (b0 , b1 , b2 , . . .) ⇐⇒ H(x), then (a0 + b0 , a1 + b1 , a2 + b2 , . . .) ⇐⇒ G(x) + H(x). ˆ (Product/convolution) If (a0 , a1 , a2 , . . .) ⇐⇒ G(x) and (b0 , b1 , b2 , . . .) ⇐⇒ H(x), then (c0 , c1 , c2 , . . .) ⇐⇒ G(x)H(x), where

ci = a0 bi + a1 bi−1 + a2 bi−2 + . . . + ai b0 To see this rule intuitively, consider expanding (a0 + a1 x + a2 x2 + . . .)(b0 + b1 x + b2 x2 + . . .).

45

MC40C Chapter 11.

Generating Functions

ˆ (Differentiation) If (a0 , a1 , a2 , . . .) ⇐⇒ G(x), then (a1 , 2a2 , 3a3 , . . .) ⇐⇒

d G(x). dx

Theorem 11.2.1. For all k ≥ 0, the generating function corresponding to the sequence   k+1 k+2 k+3 k 1 k , k , k , k , . . . is (1−x)k+1 . 1 (1−x)k+1 (1 + x + x2 + x3 + . . .)k+1 ,

Proof sketch. We will rewrite

as (1 + x + x2 + x3 + . . .)k+1 . By considering the

expansion of we see that the coefficient of xn equals the number of (k + 1)-tuples (x1 , . . . , xk+1 ) of non-negative integers whose sum is n. By stars and bars,  . the number of such tuples is n+k k 1 Alternate proof. We have that 1 + x + x2 + x3 + . . . = 1−x . Using the differentiation rule, take the derivative of both sides with respect to x, applying the chain rule on the right-hand side:   d d 1 (1 + x + x2 + x3 + . . .) = dx dx 1 − x 1 1 + 2x + 3x2 + 4x3 + . . . = (1 − x)2

Hence we see that the sequence (1, 2, 3, 4, . . .) corresponds with the generating function 1 . Taking the derivative again with respect to x: (1−x)2 2 (1 − x)3 1 1 + 3x + 6x2 + 10x4 + . . . = (1 − x)3

2 + 6x + 12x2 + 20x3 + . . . =

We can repeat this process of taking derivatives to show this result for all k.

11.3

Generating functions to solve counting problems

In many cases, we can define a generating function where the coefficient of xn corresponds to the number of ways to choose n items, or perhaps the number of outcomes whose sum is n. Example 11.3.1. Four fair six-sided dice are rolled. What is the probability that the sum of the numbers on the top faces equals 12? Solution. It is possible to brute-force this problem, but we give a slick solution using generating functions. Consider the generating function G(x) = (x + x2 + x3 + x4 + x5 + x6 )4 . By considering the expansion of G(x), it is clear that the coefficient of xn in G(x) equals the number of 46

MC40C Chapter 11.

Generating Functions

outcomes whose sum is n. Here, we will replace x + x2 + . . . + x6 with series of operations: 

6 4

G(x) = (x + . . . + x ) =

x(1 − x6 ) 1−x

= x4 (1 − x6 )4 4

6

x(1−x6 ) 1−x

and do a

4 1 (1 − x)4

= x (1 − 4x + 6x

12

− 4x

18

       3 4 5 2 +x ) + x+ x + ... 3 3 3 24

Using the product/convolution rule, we can explicitly compute the power series corresponding to G(x). However, we are only interested in the coefficient of x12 , which is     11 5 1 −4 = 125 3 3 The desired probability is

125 . 64

Example 11.3.2. A donut shop offers glazed, chocolate, and strawberry donuts. How many different ways can Richard buy two dozen donuts, given that the number of glazed donuts he buys is even, the number of chocolate donuts he buys is at most 4, and the number of strawberry donuts he buys is a multiple of 5? More generally, how many ways can he buy n ≥ 0 donuts subject to these constraints? Solution. Let G(x), C(x), and S(x) denote the ordinary generating functions corresponding to glazed, chocolate, and strawberry. Observe that we may buy 0, 2, 4, 6, . . . glazed donuts in one way, and 1, 3, 5, 7, . . . glazed donuts in zero ways. We can buy 0, 1, 2, 3, or 4 chocolate donuts in one way, and 5, 6, 7, . . . chocolate donuts in zero ways. 1 1 − x2 1 − x5 C(x) = 1 + x + x2 + x3 + x4 = 1−x 1 S(x) = 1 + x5 + x10 + x15 + . . . = 1 − x5 G(x) = 1 + x2 + x4 + x6 + . . . =

Here, the generating function corresponding to buying donuts among all three types is G(x)C(x)S(x) = (1 + x2 + x4 + . . .)(1 + x + x2 + x3 + x4 )(1 + x5 + x10 + . . .) 1 1 − x2 1 = 1 − x2 =

1 − x5 1 · 1 − x 1 − x5 1 · 1−x ·

47

MC40C Chapter 11.

Generating Functions

1 1 2 2 4 However, we already know that 1−x 2 = 1 + x + x + . . . and 1−x = 1 + x + x + . . .; thus we have G(x)C(x)S(x) = (1 + x2 + x4 + . . .)(1 + x + x2 + . . .)

We want the coefficient of x24 in the expansion of (1+x2 +x4 +. . .)(1+x+x2 +. . .); using the 2 +. . .) = product/convolution rule, we obtain 13 . More generally, (1+x2 +x4 +. . .)(1+x+x  1 + x + 2x2 + 2x3 + 3x4 + 3x5 + . . ., in which the coefficient of xn is n2 + 1. Therefore, jnk for any n ≥ 0, there are + 1 distinguishable ways to buy n donuts, subject to these 2 constraints.

11.4

Partitions of an integer n

Definition 11.4.1 (Partition). Given a positive integer n, a partition is a way of expressing n as a sum of one or more positive integers, where ordering is not important. For example, 4 has five partitions: 4, 3 + 1, 2 + 2, 2 + 1 + 1, and 1 + 1 + 1 + 1. Example 11.4.2. Given a positive integer n, show that the number of partitions of n into odd parts is the same as the number of partitions of n into distinct parts. Solution. It is possible to prove this fact using bijections, but we give a solution using generating functions. Consider the generating function F (x) = (1 + x + x2 + x3 + . . .)(1 + x3 + x6 + . . .)(1 + 5 x + x10 + . . .), so that the coefficient of xn equals the number of partitions of n into odd parts. We can express F (x) as follows: F (x) = (1 + x + x2 + x3 + . . .)(1 + x3 + x6 + . . .)(1 + x5 + x10 + . . .) 1 1 1 = · · ... 3 1 − x 1 − x 1 − x5 1 = (1 − x)(1 − x3 )(1 − x5 ) . . . Here, we will perform a clever trick: multiply top and bottom by (1−x2 )(1−x4 )(1−x6 ) . . ., so that the denominator is a product of (1 − xi ) over all i:

= However,

1−x2i 1−xi

(1 − x2 )(1 − x4 )(1 − x6 )(1 − x8 ) . . . (1 − x)(1 − x2 )(1 − x3 )(1 − x4 ) . . .

= 1 + xi , so the above simplifies to

= (1 + x)(1 + x2 )(1 + x3 )(1 + x4 ) . . . 48

MC40C Chapter 11.

Generating Functions

which is the generating function corresponding to the number of partitions of n with distinct parts.

11.5

Examples

1. (Richard Spence) A donut shop offers six different flavors of donuts. How many distinguishable ways can I buy one dozen donuts if I can only buy at most four donuts of any flavor? 2. (Yufei Zhao) Show that the number of partitions of n into parts which have at most one of each distinct even integer equals the number of partitions of n in which each part can appear at most three times. 3. (Folklore) Find the generating function for the Fibonacci numbers (i.e. find a closed form for x + x2 + 2x3 + 3x4 + 5x5 + 8x6 + · · · + Fn xn + . . . ) 4. (HMMT Feb-2010-Combinatorics-5) John needs to pay 2010 dollars for his dinner. He has an unlimited supply of 2, 5, and 10 dollar notes. In how many ways can he pay? 5. (Yufei Zhao) Show that the number of partitions of n, where each part appears at least twice, is equal to the number of partitions of n into parts all of which are divisible by 2 or 3. 6. (Folklore) Find a formula for the number of solutions in nonnegative integers to a1 + a2 + · · · + ak = n using generating functions.

11.6

Exercises

1. (PTC p194 Ex2) Find the number of ways to select 4 members from the multi-set M = {2 · b, 1 · c, 2 · d, 1 · e}. 2. (PTC p196 Ex6) Each of the 3 boys tosses a die once. Find the number of ways for them to get a total of 14. 3. (PTC p212 q11) In how many ways can 100 identical chairs be divided among 4 different rooms so that each room will have 10, 20, 30, 40 or 50 chairs? 4. (AIME-2017-I-7) For nonnegative integers a and b with a + b ≤ 6, let T (a, b) =   6  6 6 . Let S denote the sum of all T (a, b), where a and b are nonnegative a b a+b integers with a + b ≤ 6. Find the remainder when S is divided by 1000. 5. (Christopher Shao) Find the number of solutions to a + b + c = 4 if −3 ≤ a ≤ −1, 0 ≤ b ≤ 2, 3 ≤ c ≤ 5 and a, b, and c are integers. 49

MC40C Chapter 11.

Generating Functions

6. (CHMMC-2010 Winter-Team-6) Zach rolls five tetrahedral dice, each of whose faces are labeled 1, 2, 3, and 4. Compute the probability that the sum of the values of the faces that the dice land on is divisible by 3.

50

Chapter 12

Catalan Numbers 12.1

Notes

The Catalan numbers Cn are a sequence of positive integers with a wide range of combinatorial applications. We introduce one such application. Example 12.1.1. How many lattice paths can one take from (0, 0) to (n, n) by moving only right or up, without ever passing above the line y = x?  Solution. There are 2n n total paths. We will use complementary counting, by subtracting off the “bad” paths that cross above the diagonal y = x. We will construct a bijection from the set B of “bad” paths to the set A of lattice paths starting at (0, 0) and ending at (n − 1, n + 1). The bijection is as follows: consider the first time a “bad” path crosses over the diagonal y = x via an up move. To construct the corresponding lattice path in A, invert all subsequent moves, by replacing all right moves with up moves, and vice versa. The following illustration shows an example:



Then |B| = |A| =

2n n−1



. The number of “good” paths is therefore     1 2n 2n n = . be rewritten as 2n − n n n+1 n+1 n Therefore, we have the following: 51

2n n





2n n−1



. This can

MC40C Chapter 12.

Catalan Numbers

Theorem 12.1.2 (Catalan numbers). The

nth

  2n 1 . Catalan number is equal to Cn = n+1 n

Beginning with n = 0, the first few Catalan numbers are 1, 1, 2, 5, 14, 42, 132, 429, . . .

12.2

Applications, Properties of Catalan numbers

We give a few combinatorial applications involving the Catalan numbers. Try proving some of them on your own! Typically, such a proof will be bijective, by showing a bijection from the set of items you wish to count, to some set whose size you already know is Cn . For more combinatorial interpretations, see Enumerative Combinatorics (vol. 2) by R. Stanley. ˆ Cn equals the number of Dyck words of length 2n, where a Dyck word consists of n A’s and n B’s such that for all 1 ≤ i ≤ 2n, the number of A’s contained within the first i characters is greater than or equal to the number of B’s contained within the first i characters. ˆ Cn equals the number of “balanced” strings of n open and n close parentheses; (()()) and ((()(()))) are balanced, while (()))( and ()())(() are not. ˆ Cn equals the number of ways one can triangulate a convex (n + 2)-gon using nonintersecting diagonals. ˆ If there are 2n points on a circle, the number of ways to pair off the points using n non-intersecting chords is Cn . ˆ The Pn−1Catalan numbers satisfy the following recurrence relation: C0 = 1 and Cn = i=0 Ci Cn−1−i for all n ≥ 1. P n ˆ The generating function corresponding to the sequence of Catalan numbers is ∞ n=0 Cn x = √ 1− 1−4x . 2x ˆ Using Stirling’s formula, one can show that lim

n→∞

Cn 4n √ n3/2 π

= 1.

Example 12.2.1. (1993 AIME/7) Three numbers, a1 , a2 , a3 , are drawn randomly and without replacement from the set {1, 2, 3, . . . , 1000}. Three other numbers, b1 , b2 , b3 , are then drawn randomly and without replacement from the remaining set of 997 numbers. Let p be the probability that, after a suitable rotation, a brick of dimensions a1 × a2 × a3 can be enclosed in a box of dimensions b1 × b2 × b3 , with the sides of the brick parallel to the sides of the box. If p is written as a fraction in lowest terms, what is the sum of the numerator and denominator?

52

MC40C Chapter 12.

Catalan Numbers

Solution. Suppose we happen to know the values of a1 , a2 , a3 , b1 , b2 , b3 but do not know which is which; that is, suppose we are given a set of six numbers from {1, 2, . . . , 1000}, denoted x1 < x2 < x3 < x4 < x5 < x6 . For simplicity, we may even assume xi = i, so that we are given 1, 2, . . . , 6. For how many choices {a1 , a2 , a3 } can a brick with these dimensions fit inside a box of dimensions {b1 , b2 , b3 }? While this can easily be counted manually, we can in fact show that the number of  1 6 choices is given by C3 = 4 3 = 5. Indeed, consider a lattice path from (0, 0) to (3, 3) where move i is a right move if i ∈ {a1 , a2 , a3 } and move i is an up move if i ∈ {b1 , b2 , b3 }. For example, if {a1 , a2 , a3 } = {1, 2, 4} and {b1 , b2 , b3 } = {3, 5, 6}, then the corresponding lattice path is →→↑→↑↑. It can be shown that this constructs a bijection between choices  for the dimensions of the brick/box, and the set of C3 = 5 lattice paths. There are 63 = 20 5 1 ways to select {a1 , a2 , a3 }, so the probability is = =⇒ 005 . 20 4

12.3

Examples

1. (Classic) Show that       2n 2n 1 2n − = . n n−1 n+1 n 2. (Classic) Show that the number of sequences 1 ≤ a1 ≤ · · · ≤ an of integers with ai ≤ i is Cn . 3. (Classic) Show that the number of matchings of n sets of parenthesis is Cn . 4. (PTC p279 q60) Find a recurrence relation for an , the number of ways to place parentheses to indicate the order of multiplication of the n numbers x1 x2 x3 . . . xn , where n ∈ N. 5. (PTC p280 q62) For n ∈ N, let an denote the number of ways to pair off 2n distinct points on the circumference of a circle by n nonintersecting chords. Find a recurrence relation for (an ). 6. (PTC p280 q64) Find the total number of ways of arranging in a row the 2n integers a1 , a2 , . . . , an , b1 , b2 , . . . , bn with the restriction that for each i, ai precede bi , ai precede ai+1 and bi precede bi+1 .

12.4

Exercises

1. (HMMT Feb-2001-Guts-15) A beaver walks from (0, 0) to (4, 4) in the plane, walking one unit in the positive x-direction or one unit in the positive y-direction at each

53

MC40C Chapter 12.

Catalan Numbers

step. Moreover, she never goes to a point (x, y) with y > x. How many different paths can she walk? 2. (HMMT Feb-2001-Guts-7) Suppose a, b, c, d, and e are objects that we can multiply together, but the multiplication doesn’t necessarily satisfy the associative law, i.e. (xy)z does not necessarily equal x(yz). How many different ways are there to interpret the product abcde? 3. (HMMT Feb-2001-Guts-11) 12 points are placed around the circumference of a circle. How many ways are there to draw 6 non-intersecting chords joining these points in pairs? 4. (HMMT Feb-2001-Guts-29) Count the number of sequences a1 , a2 , a3 , a4 , a5 of integers such that ai ≤ 1 for all i and all partial sums (a1 , a1 + a2 , etc.) are nonnegative. 5. (HMMT Feb-2001-Guts-45) A stacking of circles in the plane consists of a base, or some number of unit circles centered on the x-axis in a row without overlap or gaps, and circles above the x-axis that must be tangent to two circles below them (so that if the ends of the base were secured and gravity were applied from below, then nothing would move). How many stackings of circles in the plane have 4 circles in the base? 6. (HMMT Feb-2002-Guts-4) How many ways are there of using diagonals to divide a regular 6-sided polygon into triangles such that at least one side of each triangle is a side of the original polygon and that each vertex of each triangle is a vertex of the original polygon?

54