0% found this document useful (0 votes)
445 views12 pages

Recursion in The AMC and AIME

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
445 views12 pages

Recursion in The AMC and AIME

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

AMC/AIME Handout

Recursion in the AMC and AIME

Author:
For:
Jeffrey Chen
AoPS
Dylan Yu

Date:
May 13, 2020

0
1
x
y 2
3
1 0

2
1

3 z
0 2

1 3
0

z2 1

2
30
1
2
y
x 3

The Catalan sequence in 3D. We will not be going over this.

To loop is human, to recurse is divine - Anonymous


The purpose of this handout is to introduce recursion and how to use it in the AMC 10/12 and the AIME.
This handout will also include practice problems at the end to help the reader learn how to use recursion. It
should be noted that recursion is not the only strategy to use in a counting problem, but it is incredibly helpful
to problems that can not be directly counted. If this document is missing anything or contains any mistakes,
feel free to shoot me an email at [email protected] or [email protected].
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

Contents

0 Acknowledgements 4

1 Introduction to Recurrence 5

2 Solving Linear Recurrences 5

3 First Counting Problem 7

4 Harder Recursion Problems 8

5 Catalan Numbers 9

6 Exercises 11

3
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

§0 Acknowledgements
This was made for the Art of Problem Solving Community out there! We would like to thank Evan Chen for his
evan.sty code. In addition, all problems in the handout were either copied from the Art of Problem Solving
Wiki or made by ourselves.

Art of Problem Solving Community

Evan Chen’s Personal Sty File

freeman66’s Website - Say Hi!

And Evan says he would like this here for evan.sty:

Boost Software License - Version 1.0 - August 17th, 2003


Copyright (c) 2020 Evan Chen [evan at evanchen.cc]
https://web.evanchen.cc/ || github.com/vEnhance

Please do not make any copies of this document without referencing this original one.

4
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

§1 Introduction to Recurrence
“To understand recursion, we must first understand recursion.” The heart of recursion is to use the previous terms
of the sequence to define future terms. It is a common technique to solve counting problems that traditional
methods (e.g. the Principal of Inclusion-Exclusion, casework, and complementary counting) cannot solve. Instead
of directly counting the number of objects, we use the first few terms, then try to find a relationship between
these terms and the larger terms. This may sound confusing at first, but with enough practice, you will certainly
be able to understand how and why it works. The best way to learn any sort of skill is with practice, and the
same is true for recursion.
Suppose we have a sequence, a1 , a2 , a3 , · · · , and assume we also have a relationship between terms of the
sequence, such as
an = 3 · an−1 .
This is what is known as a recurrence relationship: expressing a term of a sequence as some particular function
of the preceding terms. Taking our original recurrence relationship – an = 3 · an−1 , we can translate this to
every term in the sequence is 3 times the last term in the sequence. If we let the first term, a1 , equal 1, then we
can see that
a2 = 3, a3 = 9, a4 = 27,
and so on. The important thing about the recurrence relationship is that the relationship is true for all positive
integer n. For example, a40 = 3 · a39 just as a100 = 3 · a99 . Because of this, we can make substitutions between
the terms. For example, since an = 3 · an−1 and an−1 = 3 · an−2 , substituting the second equation into the first
gives us an = 9 · an−2 .
Sticking with our recurrence relation of an = 3 · an−1 , and given that a1 = 1, we can solve for the rest of the
terms of the recurrence relation. We can make a table to calculate each value of ai :
Sequence of an
i 1 2 3 4 5 6 7
ai 1 3 9 27 81 243 729

Looking at this, it seems like all ai are powers of 3. More specifically, it seems like ai = 3i−1 .

Remark 1.1. Trying a few cases can often give the desired explicit form.

We can prove this using induction, which will be introduced in our Proofs handout.
Given the first few terms of a recursion and it’s recursive relationship, it is possible to get a formula for ai .
However, in short answer competitions such as the AMC and AIME, finding the formula usually isn’t necessary.
Just by using the recursive relationships, it is possible to compute ai by making a table and expressing ai as
a function of the preceding terms. If you want to learn how to get an explicit formula for a general linear
recurrence, this Wikipedia article explains it quite well. Here we will give a brief introduction.

§2 Solving Linear Recurrences

Definition 2.1 (Characteristic Polynomial) — Let x1 , x2 , . . . , be a sequence of real numbers. Consider a


monic homogenous linear recurrence of the form

xn = cn−1 xn−1 + cn−2 xn−2 + · · · + cn−k xn−k , (∗)


where c1 , . . . , ck are real constants. The characteristic polynomial of this recurrence is defined as the
polynomial

5
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

P (x) = xk − ck−1 xk−1 − ck−2 xk−2 − · · · − c1 x − ck .

For example, let Fn be the nth Fibonacci number defined by F1 = F2 = 1, and

Fn = Fn−1 + Fn−2 ⇐⇒ Fn − Fn−1 − Fn−2 = 0,


then its characteristic polynomial is x2 − x − 1.
The roots of the polynomial can be used to write a closed form for the recurrence.

Theorem 2.2 (Explicit Form of a Linear Recurrence)


If the roots of the characteristic polynomial P are distinct, then suppose the roots are r1 , r2 , · · · , rk . Then,
there exists real constants a1 , a2 , · · · , ak such that

xn = a1 · r1n + a2 · r2n + · · · + ak · rkn .


If there are roots with multiplicity greater than 1, suppose r1 = r2 = · · · = rk1 . Then we would replace
the term a1 · rn + a2 · r2n + · · · + ak1 · rkn1 with the expression

(a1 · nk1 −1 + a2 · nk1 −2 + · · · + ak1 −1 · n + ak1 ) · rn .

The proof of this theorem is by induction, which we are not discussing in this handout. Binet’s Formula is
proved using this idea of a characteristic polynomial:

Theorem 2.3 (Binet’s Formula)


Let Fn = Fn−1 + Fn−2 and F0 = F − 1 = 1. Then the explicit form is
√ !n √ !n !
1 1+ 5 1− 5
Fn = √ − .
5 2 2

Proof. We can replace all Fk with xk . Thus,

xk = xk−1 + xk−2 ,

implying
x2 − x − 1 = 0.
The solutions to this equation are
p √
1± 1 + 4 · (−1) · (−1) −1 ± 5
x1,2 = = .
2 2
Thus, the formula must be of the form
√ !n √ !n
−1 + 5 −1 − 5
Fn = a1 + a2 ,
2 2

for constants a1 , a2 . To find these two constants, we simply plug in n = 0, 1, and get the desired result.

Thus, we can see here that solving recursions is extremely powerful. There won’t be many examples in this
handout, but constructing problems is extremely easy.

6
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

§3 First Counting Problem


While recursion might seem like a purely algebraic idea at first and something that looks fun but not useful, it
can help solve many difficult counting problems (as well as certain computer science problems).

Example 3.1
Fred wants to climb a 10 step staircase. He can climb either 1 or 2 steps at a time. In how many ways can
he climb the staircase?

Solution. We might try to count this directly. Perhaps we could list out all the possible combinations of how
Fred could walk, but using traditional methods such as complementary counting, Principle of Inclusion-Exclusion,
and casework will lengthen the time spent on this example. Instead, we will use recursion.
Instead of thinking of this problem as ”Fred wants to climb 10 stairs”, we will think of it more generally as
”Fred wants to climb n stairs.” Then, we can define

an = The number of ways for Fred to walk n steps of stairs.

With recursion in mind, we want to try to find a way to relate an to the preceding terms. Think of the last step
that Fred takes. This step can either be one stair or two stairs. If the last step is two stairs, then Fred would
have climbed n − 2 stairs and then climbed two more stairs. The number of ways for Fred to climb n − 2 stairs
is an−2 due to our definition of ai , so the number of ways for Fred to climb n − 2 stairs and then climb 2 steps is
an−2 . If the last step is one stair, then Fred would have climbed n − 1 stairs and then climbed one stair. The
number of ways for this to happen is an−1 . Since these are the only two possibilities - either Fred’s last step is
one or two stairs, we have the following equation:

an = an−1 + an−2

Now we can solve the problem. It is easy to see that a1 = 1 as Fred can climb 1 stair in only 1 way, and a2 = 2
because Fred can either climb 2 stairs in 2 one-stair steps or 1 two-stair step. We can make a table to solve for
a10 :
Sequence of an
i 1 2 3 4 5 6 7 8 9 10
ai 1 2 3 5 8 13 21 34 55 89

Thus, our answer is 89 .

Some of you may recognize this sequence as the Fibonacci sequence, which appears quite often in counting
problems and especially ones that use recursion. Knowing the first few elements of the Fibonacci sequence can
sometimes be handy for certain speed based competitions. As a side note, the Fibonacci numbers have a lot of
interesting properties. For those unaware,

Definition 3.2 (Fibonacci Sequence) — The Fibonacci sequence is a sequence of integers in which the
first and second terms are both equal to 1 and each subsequent term is the sum of the two preceding it.
The first few terms are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, . . ..

The Fibonacci sequence can be written recursively as F1 = F2 = 1 and Fn = Fn−1 + Fn−2 for n ≥ 3. This is the
simplest nontrivial example of a linear recursion with constant coefficients.

7
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

§4 Harder Recursion Problems

Example 4.1 (2007 AMC 12)


Call a set of integers spacy if it contains no more than one out of any three consecutive integers. How many
subsets of {1, 2, 3, . . . , 12}, including the empty set, are spacy?

Solution. Counting directly seems to be somewhat difficult since there would be a lot of casework involved, so
we think of recursion. We will define

an = The number of spacy subsets of the set {1, 2, . . . , n.}

Next, we will try to relate an to the terms preceding it. For each subset, we can put it into one of two groups:
whether the subset contains n or does not contain n. If the subset contains n, then because it is spacy, that
subset cannot contain n − 1 or n − 2. Thus, this spacy subset is simply a spacy subset of {1, 2, . . . , n − 3} with
an appended n. Thus, there must be an−3 spacy subsets that contain n. If a spacy subset does not contain n,
then it is also a spacy subset of {1, 2, . . . , n − 1}, so there are an−1 spacy subsets that do not contain n. Since a
spacy subset either contains n or does not contain n, we have exhausted all the possibilities. This results in the
following recursive relationship:

an = an−1 + an−3

We can calculate by hand the first few values of ai . We have a1 = 2 since the two spacy subsets are {} and {1}.
Similarly, a2 = 3 since the spacy subsets are {}, {1}, {2}, and a3 = 4 since the spacy subsets are {}, {1}, {2}, {3}.
Now, with these values, we can make a table and solve for a12 :
Sequence of an
i 1 2 3 4 5 6 7 8 9 10 11 12
ai 2 3 4 6 9 13 19 28 41 60 88 129

Thus, our final answer is a12 = 129 .

Example 4.2 (AIME 2006)


A collection of 8 cubes consists of one cube with edge-length k for each integer k, 1 ≤ k ≤ 8. A tower is to
be built using all 8 cubes according to the following 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.

How many towers can be constructed?

Again, we will solve this problem recursively. Define

an = The number of different towers given n cubes with edge-lengths 1, 2, . . . n

Then we look at the cube with edge-length n. This cube can either be on top of the cube with edge length n − 1,
on top of the cube with edge length n − 2, or it could be at the bottom of the tower. Thus, for each configuration
with n − 1 cubes, there are 3 ways to create a configuration with n cubes, and we have the following equation:

an = 3 · an−1

Since a2 = 2 (for all n ≥ 3) as we can either have the cube with edge-length 1 on the bottom or the cube with
edge-length 2 on the bottom, we have a8 = 36 · 2 = 1458 .

8
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

Observe that we can’t say that a2 = 3 · a1 . This is because our recurrence relationship breaks down when
n = 2. We assumed that the cube with edge-length n can either be placed on the bottom, above the cube with
edge-length n − 1, or above the cube with edge-length n − 2; however, when there is no cube with edge-length
n − 2, (as when we substitute n = 2 this becomes 0), the recurrence is no longer an = 3 · an−1 . Sometimes
for recurrences we can’t directly recur from the very beginning and have to find the first few terms before the
recurrence actually applies.

§5 Catalan Numbers
The Catalan numbers are best presented through the following problem:

Example 5.1
How many 2n step paths are there from (0, 0) to (n, n) such that for each (x, y) on that path, x ≥ y?

Solution. We can illustrate the problem for the n = 3 case here:

Counting by hand we can see that there are 5 paths. But we could try to do this recursively. We will define

Cn = The number of paths from (0, 0) to (n, n) such that for each (x, y) on that path, x ≥ y.

Let the point (i, i) be the first point in a path where x = y, besides the point (0, 0). Then, we can see that the
number of ways to get from (i, i) to (n, n) is Cn−i . However, the number of ways to get from (0, 0 to (i, i) is
Ci−1 . Note that if (i, i) is the first point in the path where x = y, then the path had to go from (0, 0) to (1, 0) to
(i, i − 1) to (i, i). Then, the portion of the path from (1, 0) to (i, i − 1) must always be below the line x ≥ y + 1,
as illustrated below:

As we can see, the path never goes above the line x = y + 1 except at the very end. Then, the number of paths
that goes from (1, 0) to (i, i − 1) that doesn’t go above the line x = y + 1 has to be Ci as we can just translate
that portion of the path 1 unit to the left, and we get a graph from (0, 0) to (i − 1, i − 1) that never goes above
the line x = y. Therefore, the number of paths that intersect the line y = x first at point (i, i) will be Ci−1 Cn−i .
Summing this over all i, as the path can only touch the line x = y first at exactly one point, we get the following
recurrence:

9
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

n−1
X
Cn = C0 Cn−1 + C1 Cn−2 + . . . + Cn−2 C1 + Cn−1 C0 = Ci Cn−i−1 .
i=0

We have found our recurrence relationship. This sequence is called the Catalan numbers, and it provides the
solution to many problems.

Theorem 5.2 (Catalan Numbers)


The explicit formula for the nth Catalan number is
 
1 2n
.
n+1 n

We won’t prove this in the handout.


As previously discussed, many other problems also have the Catalan numbers as their solutions. This is
because we can form a bijection between such a problem with example 4.1. One of those problems is shown
below:

Example 5.3
How many ways are there to arrange n open brackets ”[” and n closed brackets ”]” such that when read left
to right, the number of closed brackets is less than or equal to the number of open brackets?

Solution. We could try to form the recurrence again, but instead, we use a clever bijection to example 4.1. We
place an duck on point (0, 0). Then, whenever we have an open bracket ”[”, we will move the duck one unit
to the right. Whenever we have a closed bracket, we will move the duck one unit up. Since there are n open
brackets and n closed brackets, the duck will end up on point (n, n), and since the number of closed brackets is
always less than or equal to the number of open brackets, the duck will never go above the line x = y. Thus, the
solution to this problem is simply the Catalan numbers Cn .

10
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

§6 Exercises

Exercise 6.1. How many ways are there to tile an 10 by 2 board with 1 by 2 dominoes such that each
domino covers exactly two squares and no domino overlaps?

Exercise 6.2 (AMC 12 2019). How many binary sequences (sequences of 0’s and 1’s) of length 19 are there
that begin with a 0, end with a 0, contain no two consecutive 0’s, and contain no three consecutive 1’s?

Exercise 6.3 (AIME 2015). There are 210 = 1024 possible 10-letter strings in which each letter is either an
A or a B. Find the number of such strings that do not have more than 3 adjacent letters that are identical.

Exercise 6.4. Given a regular 2n-gon, how many ways are there to pair vertices and draw line segments
between those vertices such that no two line segments intersect?

Exercise 6.5 (Charmander3333’s Contributor Test). Ms. Red wants to create a 10 question test for her
students. Each question is multiple choice with 4 answer choices, a, b, c, and d. How many ways are there
for Ms. Red to create the 10 question test if every 5 consecutive questions must contain at least one of each
of the four answer choices?

Exercise 6.6 (AIME 2001). A mail carrier delivers mail to the nineteen houses on the east side of Elm
Street. The carrier notices that no two adjacent houses ever get mail on the same day, but that there are
never more than two houses in a row that get no mail on the same day. How many different patterns of
mail delivery are possible?

Exercise 6.7 (AMC 12 A 2019). Let 4A0 B0 C0 be a triangle whose angle measures are exactly 59.999◦ ,
60◦ , and 60.001◦ . For each positive integer n, define An to be the foot of the altitude from An−1 to line
Bn−1 Cn−1 . Likewise, define Bn to be the foot of the altitude from Bn−1 to line An−1 Cn−1 , and Cn to be the
foot of the altitude from Cn−1 to line An−1 Bn−1 . What is the least positive integer n for which 4An Bn Cn
is obtuse?

Exercise 6.8 (AIME 2016). The figure below shows a ring made of six small sections which you are to
paint on a wall. You have four paint colors available and will paint each of the six sections a solid color.
Find the number of ways you can choose to paint each of the six sections if no two adjacent section can be
painted with the same color?

11
Copyright © 2020 by Euclid’s Orchard. All rights reserved.
Jeffrey Chen and Dylan Yu (May 13, 2020) Recursion in the AMC and AIME

Exercise 6.9. Given a stairstep shape of size n by n, where the n = 4 version is shown below,

how many ways are there to tile this n by n stairstep shape with n rectangles with integer lengths?

Exercise 6.10 (AIME 2018). Find the number of permutations of 1, 2, 3, 4, 5, 6 such that for each k with
1 ≤ k ≤ 5, at least one of the first k terms of the permutation is greater than k

Exercise 6.11 (AoPS Mock Contest). How many ways can an ant walk from point A to point B along the
arrows using exactly 8 steps?
A

Exercise 6.12 (Intermediate Counting and Probability). Count the number of sequences of integers
a1 , a2 , a3 , . . . , an with ai ≤ 1 for all i such that all partial sums a1 + a2 + . . . + ai are non-negative.

12
Copyright © 2020 by Euclid’s Orchard. All rights reserved.

You might also like