Setting Up Recurrences
A recurrence counts a large problem in terms of smaller versions of itself. To build one:
- Define the sequence precisely. Let be the number of ways to do the task of “size” . Being sloppy here is the #1 source of errors — write a one-sentence definition.
- Condition on a first (or last) choice. Look at the object and split into cases based on one feature: the first tile, the last step, whether an element is used, the height of the last column, etc.
- Express each case using smaller . Each case should leave a strictly smaller sub-problem of the same type, so it is counted by for some .
- Nail the base cases. Determine (or ) directly by hand. Count the “empty” object carefully: usually .
The recurrence plus base cases determines every term.
Recursion counts by relating a size- problem to smaller ones: tilings, strings with forbidden patterns, and lattice paths all satisfy recurrences, often Fibonacci-like. Catalan numbers count balanced parentheses, non-crossing paths and triangulations. Generating functions package a whole sequence into one power series, where recurrences become algebra.
Let be the number of ordered sequences of s and s summing to (order matters). Condition on the first number in the sequence:
- If it is a , the rest sums to : that is ways.
- If it is a , the rest sums to : that is ways.
So . Base cases: (the empty sequence) and . This gives — the Fibonacci numbers.
Setting up a recurrence with the wrong initial values. Compute the first two or three terms by hand — a correct recurrence with wrong seeds gives a wrong sequence forever.
Tips. (1) Prefer conditioning on the first or last element — it usually leaves a clean sub-problem. (2) Always sanity-check by hand-counting against your formula. (3) Decide up front whether order matters and whether should be or .
Let with . Compute , , and .
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: Arithmetic recurrence. The rule adds at every step, starting from . Iterate term by term:
Thus .
Fibonacci & Tiling / Domino Problems
The Fibonacci numbers satisfy
giving Many tiling problems reduce to this.
Square–domino tilings. Let be the number of ways to tile a strip using squares and dominoes. Look at the tile covering the last cell: a square (leaving a strip) or a domino (leaving a strip). So with , i.e. .
Let be the number of ways to tile a board with dominoes. Consider the leftmost column:
- One vertical domino fills the column, leaving a board: ways.
- Two horizontal dominoes fill the first two columns, leaving a board: ways.
Hence , with , . So ; e.g. a board has tilings.
Allowing a horizontal domino alone in the first column. If the top-left cell is covered by a horizontal domino, the cell below it cannot be covered by a vertical one (that would overlap) and must also be a horizontal domino, so the two horizontals always come as a stacked pair covering two columns. Counting "horizontal on top, anything below" as a separate case adds tilings that do not exist; the recurrence has exactly the two cases and .
Tips. The recurrence comes from “what covers the boundary cell?” Different tile sets change the recurrence: squares + dominoes + trominoes on a strip give . Watch indexing: confirm which Fibonacci index your base cases land on.
You climb a staircase of steps, taking either or steps at a time. Let be the number of ways to reach the top. Write a recurrence for and compute .
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: Staircase. Let be the number of ways to climb steps using -step and -step moves. Condition on the last move: if it is a single step, the first steps can be climbed in ways; if it is a double step, the first steps can be climbed in ways. These cases are disjoint and exhaustive, so
Base cases: (do nothing) and . Iterate:
So the recurrence is and .
State-Based Counting Recursions
When the next choice depends on the current situation, define one sequence per state and let them recurse together. Steps:
- Identify the finite information (the “state”) you must remember to extend a valid object by one step.
- Define = number of length- objects ending in each state.
- Write transition equations: each state's next value is a sum over states that may legally precede it.
- The answer is usually the sum of all states at length .
This is the “transfer matrix” / finite-automaton viewpoint.
Count length- binary strings with no “11”. Track the last bit. Let = number ending in , = number ending in .
- A string ending in can be preceded by anything: .
- A string ending in must have before it: .
With , the total satisfies (Fibonacci again!), giving
Tips. Keep the state as small as possible — only remember what the next transition needs. If a constraint says “no three in a row,” your state is the length of the current run, so you may need two or three coupled sequences.
How many binary strings of length have no two consecutive s?
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: Track (ending in ) and (ending in ), with and . From :
The total is .
Catalan Numbers
The Catalan numbers are
First values:
They count an astonishing number of things. Three canonical interpretations:
- Lattice paths / ballots: monotonic paths from to using steps right/up that never cross above the diagonal . Equivalently, sequences of s and s with every partial sum .
- Balanced parentheses: the number of ways to correctly match pairs of parentheses (every prefix has ).
- Triangulations: the number of ways to cut a convex -gon into triangles using non-crossing diagonals.
Other appearances: binary trees with internal nodes, non-crossing handshakes among people, mountain ranges, and stack-sortable permutations.
How many ways to fully parenthesize a product of factors, e.g. ? This is :
Why ? In a balanced string, the first “(” closes at some point, splitting the string into an inner balanced block (size ) and a following balanced block (size ). Summing over the split point gives the convolution. This same split proves the triangulation and binary-tree counts.
Assuming symmetry splits the paths in half. Of the paths to , it is tempting to say "half stay below the diagonal", giving . But most paths cross the diagonal, spending time on both sides, so they belong to neither half. Only stay below. The reflection argument counts the bad ones exactly: of them, and .
Tips. If a counting problem involves “never falls behind,” “non-crossing,” or “a valid bracket/matching structure,” suspect Catalan. Memorize through : . The ratio makes them fast to extend.
In how many ways can a convex hexagon be cut into triangles by non-crossing diagonals?
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: A convex -gon has triangulations; a hexagon is . From the convolution, , which matches . The convolution is the triangulation argument itself: the triangle on one fixed side splits the rest into two smaller polygons.
Generating Functions (introduction)
A (ordinary) generating function packages a sequence into one formal power series
The exponent of is a “label” tracking a total (size, weight, sum), and the coefficient counts objects with that total. The magic:
If counts choices for part 1 (weighted by size) and counts part 2, then the product has -coefficient — exactly the number of ways to split total between the two parts. Useful building blocks:
In how many ways can you make cents using pennies (1c), nickels (5c), and dimes (10c), unlimited supply, order irrelevant? Each coin type contributes a geometric factor tracking how much value it supplies:
The coefficient of in is the answer. For instance : pennies; (nickels); a nickel pennies; one dime. Products of GFs automatically handle “distribute the total among independent parts.”
Tips. Treat as a formal symbol — convergence does not matter. “Choose one of several” becomes a sum of terms; “do several things independently” becomes a product of series. To read off a coefficient, use or partial fractions.
Find the coefficient of in , and say what it counts.
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: The factor chooses how much of the total comes from s (, or ); the factor fills the rest with s in exactly one way. So the coefficient is , counting the ways to write as an unordered sum of s and s: , , .
Solving Simple Linear Recurrences
For a linear recurrence with constant coefficients
guess . Substituting and dividing by gives the characteristic equation
- Distinct roots : the general solution is .
- Repeated root : use .
Fix from two initial values. The same idea extends to order : a degree- characteristic polynomial with roots.
Given . Characteristic equation: , i.e. , so and . Thus
Initial conditions: and . Solving, , so
Check: . ✓
Tips. Bring everything to one side so the characteristic polynomial is clear. Complex roots are fine — they produce oscillating solutions. For a nonhomogeneous recurrence (), add a particular solution (try a constant for constant , a linear guess for linear ) to the homogeneous solution.
Solve with , .
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: Characteristic equation , i.e. , so . Then and , giving , :
Check: and .
Going Deeper: Closed Forms and Proofs
(A) The Catalan closed form by reflection. Count lattice paths from to (steps R and U) that stay weakly below the diagonal. Total paths: . A bad path touches the line . Reflect the portion of a bad path after its first touch across : this bijects bad paths with all paths from to , of which there are . Hence
(B) Solving a recurrence with a generating function. Let . The convolution says . Solving the quadratic,
and expanding by the binomial series recovers . This “turn the recurrence into an equation for , solve, expand” pipeline is the general method.
(C) Binet's formula for Fibonacci. The characteristic equation has roots and . Then
Since , is the nearest integer to , so Fibonacci numbers grow like .
The Fibonacci GF is . Factor the denominator using and split by partial fractions:
which reads off Binet's formula directly. Partial fractions on -type denominators is the bridge from recurrence to closed form.
Big picture. Recursion, Catalan numbers, and generating functions are one connected toolkit. Recursion is how you discover a count by conditioning on a first/last choice or a state. Generating functions are how you package and solve those recurrences — products encode independent choices, and solving an algebraic equation for yields closed forms. Catalan numbers are the flagship example where all three views (a convolution recurrence, a reflection/bijection argument, and a GF quadratic) meet in one answer. When you see “count in terms of smaller cases,” set up ; when you see “combine independent totals,” multiply GFs; when you see “non-crossing / balanced / never-behind,” reach for Catalan.
How many ways are there to tile a board completely with dominoes?
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: Tiling a board with dominoes. Let count domino tilings of a board. Consider the leftmost column: it is covered either by one vertical domino (leaving a board) or by the left halves of two horizontal dominoes stacked (leaving a board). Hence with :
So .
Nonhomogeneous & Higher-Order Linear Recurrences
A linear recurrence with a forcing term,
is solved by
where is the general solution of the homogeneous part (characteristic roots, as before) and is any one particular solution. To find , guess a form matching and solve for its constants:
Resonance (the crucial trap). If your guess already solves the homogeneous equation — e.g. but is a characteristic root, or is constant but is a root — multiply the guess by (by if is a root of multiplicity ). This is the same “multiply by for a repeated root” rule seen in the homogeneous case.
Solve with .
Homogeneous part: , so and .
Particular part: the natural guess is resonant because is already a root. Multiply by : try . Substituting,
Divide by : , i.e. , giving . So .
Combine and fit: . From and we get . Thus
Check: , and . ✓
Tips. (1) Always solve the homogeneous roots first — you cannot detect resonance until you know them. (2) A constant forcing term with a root needs the guess (not ). (3) If is a sum of pieces, find a particular solution for each piece separately and add. (4) Fit the constants using the full solution , never the homogeneous part alone.
Solve with .
Work it on paper before revealing the answer.
Show the answerHide the answer
Answer: Homogeneous part: , so . The forcing term is a constant and is not a root, so try : gives . Then , and gives :
Check: , , , and . (This counts the moves in the Tower of Hanoi.)
The Transfer-Matrix Method
A coupled linear recurrence among finitely many states is one matrix acting on a state vector. If collects the state values at step and , then
For the Fibonacci recurrence, taking ,
The matrix's eigenvalues are exactly the characteristic roots , which is why (hence every entry) is a combination of and — another route to Binet's formula. Taking determinants of the boxed identity gives instantly (Cassini's identity).
Counting walks. If is the adjacency matrix of a (multi)graph, then counts walks of length from vertex to , and counts closed walks. This packages “count paths through states” as matrix powers.
Three vertices of a triangle are all mutually adjacent. How many closed walks of length start and end at vertex ? The adjacency matrix is where is all-ones:
Its eigenvalues: has eigenvalues , so has eigenvalues . By symmetry every diagonal entry of is equal, and , so
Check : closed walks number , and . ✓ For we get , the two directed triangles and . This is the standard AIME-style “ant walks on a solid/graph and returns home” setup.
Tips. (1) Order- scalar recurrences become companion matrices whose characteristic polynomial is the recurrence's. (2) For symmetric transition structures, diagonalizing via eigenvalues turns into a clean closed form — look for an all-ones or circulant pattern. (3) and identities (Cassini) fall out for free. (4) On a highly symmetric graph, “lump” equivalent vertices into one state to shrink the matrix.
The Cycle Lemma & the Ballot Problem
The reflection principle is one proof of the Catalan/ballot counts; the cycle lemma is a slicker, purely combinatorial one.
Cycle Lemma (Dvoretzky–Motzkin). Take any sequence of steps that are 's and 's summing to (so ups and downs). Among its cyclic rotations, exactly one has all partial sums strictly positive.
Ballot Theorem. In an election where gets votes and gets votes, the number of orderings of the ballots in which is strictly ahead throughout is
Catalan is the boundary case : an ordering in which stays strictly ahead must open with an vote, and the remaining votes ( each) form a path to that never rises above the diagonal. The ballot formula gives .
In how many ways can people holding a $5 bill and people holding a $10 bill line up at a box office that sells $5 tickets and starts with an empty till, so that the cashier can always give change?
Model each $5 as and each $10 as . The line works exactly when every partial sum is . Now put an imaginary extra $5 customer at the front. The new sequence has steps and steps , total , and its partial sums are the old ones plus : the line works exactly when every partial sum of the new sequence is strictly positive. Conversely, a sequence of this kind with all partial sums positive must start with , and deleting that first step gives a working line.
There are sequences with ups and downs. Their rotations are all different (a sequence built from a repeated block would have a total divisible by the number of blocks, and the total is ), so they fall into rotation classes. By the cycle lemma each class contains exactly one sequence with all partial sums positive. Hence
For : , and indeed only $5 $5 $10 $10 and $5 $10 $5 $10 work. ✓
Tips. (1) The cycle lemma also proves the Fuss–Catalan numbers (paths with up-steps and down-steps ) — same one-good-rotation idea. (2) “Strictly ahead” vs. “never behind” shifts an index by one; recount a tiny case to pin it down. (3) When a problem says “running total never goes negative” and you can cyclically shift without changing the count, reach for the cycle lemma instead of reflection.
Exponential Generating Functions
When objects are built on labeled elements (people, positions that are distinguishable), the right bookkeeping tool is the exponential generating function
The key rule mirrors the ordinary case but with a binomial-flavored product:
The appears because you first choose which labels go to the -part. Building blocks:
The Exponential Formula passes from “connected” pieces to arbitrary disjoint unions of them (set partitions into blocks, permutations into cycles, graphs into components).
A derangement is a permutation with no fixed point; let be their count. Every permutation splits its labels into a set of fixed points and a derangement of the rest:
In EGF language this is a product: (all permutations) (choose fixed points) (derange the rest), i.e.
Reading off the coefficient of ,
the familiar inclusion–exclusion formula, and is the nearest integer to . From one also reads the recurrences and .
Big picture. Use an ordinary GF when parts combine by “split the total” (unlabeled: coins, compositions, tilings); use an exponential GF when parts combine by “distribute distinct labels” (labeled: permutations, set partitions, surjections). The dictionary — product independent combination, disjoint components — lets you write the answer's generating function directly from a structural description, then extract by expanding.
Why It Works
Why : paths from to that never cross above the diagonal are all paths minus the bad ones, and reflecting a bad path after its first illegal step gives a bijection with paths to , of which there are . The difference simplifies to the formula. Generating functions work because multiplying series adds exponents — a convolution — which is exactly the structure of "choose a first part, then the rest".
Do not read a proof the way you read a rule. Cover the last line, ask what the previous line forces, and only then uncover it. If a step feels like magic, that is the step to work by hand with a concrete number.
Formulas, Proofs & Tips
What it means. Define a term from earlier terms; Catalan numbers count balanced structures.
Example. Fibonacci: ; and .
Why it works. Fibonacci-style counts split on the last step: a tiling ending in a single square leaves ways, one ending in a domino leaves , and the cases do not overlap. Catalan counts paths that never dip below the axis — the reflection argument removes exactly bad paths.
Tip. Always state the base cases; a recursion without them defines nothing.