Recursion, Catalan Numbers & Generating Functions

Study Sheet

Recursion, Catalan Numbers & Generating Functions

Competition counting & probability, Unit 6

Setting Up Recurrences

Concept
The core idea

A recurrence counts a large problem in terms of smaller versions of itself. To build one:

  • [leftmargin=*,itemsep=1pt]
  • Define the sequence precisely. Let ana_n be the number of ways to do the task of “size” nn. 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 aka_k. Each case should leave a strictly smaller sub-problem of the same type, so it is counted by aka_{k} for some k<nk<n.
  • Nail the base cases. Determine a0a_0 (or a1a_1) directly by hand. Count the “empty” object carefully: usually a0=1a_0=1.

The recurrence plus base cases determines every term.

Example
Worked example --- ways to make a total of nn with 1s and 2s

Let ana_n be the number of ordered sequences of 11s and 22s summing to nn (order matters). Condition on the first number in the sequence:

  • [leftmargin=*,itemsep=1pt]
  • If it is a 11, the rest sums to n1n-1: that is an1a_{n-1} ways.
  • If it is a 22, the rest sums to n2n-2: that is an2a_{n-2} ways.

So an=an1+an2a_n=a_{n-1}+a_{n-2}. Base cases: a0=1a_0=1 (the empty sequence) and a1=1a_1=1. This gives 1,1,2,3,5,8,1,1,2,3,5,8,\dots --- the Fibonacci numbers.

Tip

Tips. (1) Prefer conditioning on the first or last element --- it usually leaves a clean sub-problem. (2) Always sanity-check by hand-counting a1,a2,a3a_1,a_2,a_3 against your formula. (3) Decide up front whether order matters and whether a0a_0 should be 11 or 00.

Fibonacci & Tiling / Domino Problems

Concept
Fibonacci from tilings

The Fibonacci numbers satisfy

fn=fn1+fn2,f1=f2=1,f_n=f_{n-1}+f_{n-2},\qquad f_1=f_2=1,

giving 1,1,2,3,5,8,13,21,34,55,1,1,2,3,5,8,13,21,34,55,\dots Many tiling problems reduce to this.

Square--domino tilings. Let tnt_n be the number of ways to tile a 1×n1\times n strip using 1×11\times1 squares and 1×21\times2 dominoes. Look at the tile covering the last cell: a square (leaving a 1×(n1)1\times(n-1) strip) or a domino (leaving a 1×(n2)1\times(n-2) strip). So tn=tn1+tn2t_n=t_{n-1}+t_{n-2} with t0=1, t1=1t_0=1,\ t_1=1, i.e. tn=fn+1t_n=f_{n+1}.

Example
Worked example --- tiling a 2×n2\times n board with dominoes

Let DnD_n be the number of ways to tile a 2×n2\times n board with 1×21\times2 dominoes. Consider the leftmost column:

  • [leftmargin=*,itemsep=1pt]
  • One vertical domino fills the column, leaving a 2×(n1)2\times(n-1) board: Dn1D_{n-1} ways.
  • Two horizontal dominoes fill the first two columns, leaving a 2×(n2)2\times(n-2) board: Dn2D_{n-2} ways.

Hence Dn=Dn1+Dn2D_n=D_{n-1}+D_{n-2}, with D0=1D_0=1, D1=1D_1=1. So Dn=fn+1D_n=f_{n+1}; e.g. a 2×42\times4 board has D4=5D_4=5 tilings.

Tip

Tips. The recurrence comes from “what covers the boundary cell?” Different tile sets change the recurrence: squares + dominoes + trominoes on a strip give tn=tn1+tn2+tn3t_n=t_{n-1}+t_{n-2}+t_{n-3}. Watch indexing: confirm which Fibonacci index your base cases land on.

State-Based Counting Recursions

Concept
Counting with states

When the next choice depends on the current situation, define one sequence per state and let them recurse together. Steps:

  • [leftmargin=*,itemsep=1pt]
  • Identify the finite information (the “state”) you must remember to extend a valid object by one step.
  • Define an,bn,a_n,b_n,\dots = number of length-nn 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 nn.

This is the “transfer matrix” / finite-automaton viewpoint.

Example
Worked example --- binary strings with no two consecutive 1s

Count length-nn binary strings with no “11”. Track the last bit. Let AnA_n = number ending in 00, BnB_n = number ending in 11.

  • [leftmargin=*,itemsep=1pt]
  • A string ending in 00 can be preceded by anything: An=An1+Bn1A_n=A_{n-1}+B_{n-1}.
  • A string ending in 11 must have 00 before it: Bn=An1B_n=A_{n-1}.

With A1=1,B1=1A_1=1,B_1=1, the total Tn=An+BnT_n=A_n+B_n satisfies Tn=Tn1+Tn2T_n=T_{n-1}+T_{n-2} (Fibonacci again!), giving T1=2,T2=3,T3=5,T_1=2,T_2=3,T_3=5,\dots

Tip

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.

Catalan Numbers

Concept
The Catalan numbers

The Catalan numbers are

Cn=1n+1(2nn)=(2nn)(2nn+1),Cn+1=i=0nCiCni.C_n=\frac{1}{n+1}\binom{2n}{n}=\binom{2n}{n}-\binom{2n}{n+1}, \qquad C_{n+1}=\sum_{i=0}^{n}C_i\,C_{n-i}.

First values:

n0123456Cn11251442132\begin{array}{c|ccccccc} n & 0 & 1 & 2 & 3 & 4 & 5 & 6\\\hline C_n & 1 & 1 & 2 & 5 & 14 & 42 & 132 \end{array}

They count an astonishing number of things. Three canonical interpretations:

  • [leftmargin=*,itemsep=1pt]
  • Lattice paths / ballots: monotonic paths from (0,0)(0,0) to (n,n)(n,n) using steps right/up that never cross above the diagonal y=xy=x. Equivalently, sequences of nn +1+1s and nn 1-1s with every partial sum 0\ge 0.
  • Balanced parentheses: the number of ways to correctly match nn pairs of parentheses (every prefix has #(\#( \ge #)\#)).
  • Triangulations: the number of ways to cut a convex (n+2)(n+2)-gon into triangles using non-crossing diagonals.

Other appearances: binary trees with nn internal nodes, non-crossing handshakes among 2n2n people, mountain ranges, and stack-sortable permutations.

Example
Worked example --- parenthesizations and the convolution

How many ways to fully parenthesize a product of 44 factors, e.g. abcda\cdot b\cdot c\cdot d? This is C3=5C_3=5:

((ab)c)d,(a(bc))d,(ab)(cd),a((bc)d),a(b(cd)).((ab)c)d,\quad (a(bc))d,\quad (ab)(cd),\quad a((bc)d),\quad a(b(cd)).

Why Cn+1=CiCniC_{n+1}=\sum C_iC_{n-i}? In a balanced string, the first “(” closes at some point, splitting the string into an inner balanced block (size ii) and a following balanced block (size nin-i). Summing over the split point gives the convolution. This same split proves the triangulation and binary-tree counts.

Tip

Tips. If a counting problem involves “never falls behind,” “non-crossing,” or “a valid bracket/matching structure,” suspect Catalan. Memorize C0C_0 through C5C_5: 1,1,2,5,14,421,1,2,5,14,42. The ratio Cn+1/Cn=2(2n+1)n+2C_{n+1}/C_n=\frac{2(2n+1)}{n+2} makes them fast to extend.

Generating Functions (introduction)

Concept
Series as bookkeeping devices

A (ordinary) generating function packages a sequence a0,a1,a2,a_0,a_1,a_2,\dots into one formal power series

A(x)=n0anxn.A(x)=\sum_{n\ge 0}a_n x^n .

The exponent of xx is a “label” tracking a total (size, weight, sum), and the coefficient counts objects with that total. The magic:

choosing independently    multiplying generating functions.\textbf{choosing independently} \;\longleftrightarrow\; \textbf{multiplying generating functions.}

If A(x)A(x) counts choices for part 1 (weighted by size) and B(x)B(x) counts part 2, then the product A(x)B(x)A(x)B(x) has xnx^n-coefficient kakbnk\sum_k a_k b_{n-k} --- exactly the number of ways to split total nn between the two parts. Useful building blocks:

11x=n0xn,11xk=j0xjk,(1+x)m=n(mn)xn.\frac{1}{1-x}=\sum_{n\ge0}x^n,\qquad \frac{1}{1-x^k}=\sum_{j\ge0}x^{jk},\qquad (1+x)^m=\sum_{n}\binom{m}{n}x^n .
Example
Worked example --- coins as a product of GFs

In how many ways can you make nn 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:

G(x)=11xpennies11x5nickels11x10dimes.G(x)=\underbrace{\frac{1}{1-x}}_{\text{pennies}}\cdot\underbrace{\frac{1}{1-x^{5}}}_{\text{nickels}}\cdot\underbrace{\frac{1}{1-x^{10}}}_{\text{dimes}} .

The coefficient of xnx^{n} in G(x)G(x) is the answer. For instance [x10]G(x)=4[x^{10}]G(x)=4: 1010 pennies; 5+55{+}5 (nickels); a nickel +5+5 pennies; one dime. Products of GFs automatically handle “distribute the total among independent parts.”

Tip

Tips. Treat xx 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 1(1x)k=n(n+k1k1)xn\frac{1}{(1-x)^{k}}=\sum_n\binom{n+k-1}{k-1}x^n or partial fractions.

Solving Simple Linear Recurrences

Concept
The characteristic-equation method

For a linear recurrence with constant coefficients

an=c1an1+c2an2,a_n=c_1a_{n-1}+c_2a_{n-2},

guess an=rna_n=r^n. Substituting and dividing by rn2r^{n-2} gives the characteristic equation

r2=c1r+c2.r^2=c_1 r + c_2 .
  • [leftmargin=*,itemsep=1pt]
  • Distinct roots r1r2r_1\ne r_2: the general solution is an=αr1n+βr2na_n=\alpha\, r_1^{\,n}+\beta\, r_2^{\,n}.
  • Repeated root rr: use an=(α+βn)rna_n=(\alpha+\beta n)\,r^{\,n}.

Fix α,β\alpha,\beta from two initial values. The same idea extends to order kk: a degree-kk characteristic polynomial with kk roots.

Example
Worked example --- solving an=5an16an2a_n=5a_{n-1}-6a_{n-2}

Given a0=0, a1=1a_0=0,\ a_1=1. Characteristic equation: r2=5r6r^2=5r-6, i.e. r25r+6=0r^2-5r+6=0, so (r2)(r3)=0(r-2)(r-3)=0 and r=2,3r=2,3. Thus

an=α2n+β3n.a_n=\alpha\, 2^{n}+\beta\, 3^{n}.

Initial conditions: a0=α+β=0a_0=\alpha+\beta=0 and a1=2α+3β=1a_1=2\alpha+3\beta=1. Solving, β=1, α=1\beta=1,\ \alpha=-1, so

an=3n2n.a_n=3^{n}-2^{n}.

Check: a2=94=5=5(1)6(0)a_2=9-4=5=5(1)-6(0). ✓

Tip

Tips. Bring everything to one side so the characteristic polynomial is clear. Complex roots are fine --- they produce oscillating solutions. For a nonhomogeneous recurrence (an=c1an1++g(n)a_n=c_1a_{n-1}+\dots+g(n)), add a particular solution (try a constant for constant gg, a linear guess for linear gg) to the homogeneous solution.

Going Deeper: Closed Forms and Proofs

Concept
Three derivations worth knowing

(A) The Catalan closed form by reflection. Count lattice paths from (0,0)(0,0) to (n,n)(n,n) (steps R and U) that stay weakly below the diagonal. Total paths: (2nn)\binom{2n}{n}. A bad path touches the line y=x+1y=x+1. Reflect the portion of a bad path after its first touch across y=x+1y=x+1: this bijects bad paths with all paths from (0,0)(0,0) to (n1,n+1)(n-1,n+1), of which there are (2nn+1)\binom{2n}{n+1}. Hence

Cn=(2nn)(2nn+1)=1n+1(2nn).C_n=\binom{2n}{n}-\binom{2n}{n+1}=\frac{1}{n+1}\binom{2n}{n}.

(B) Solving a recurrence with a generating function. Let C(x)=n0CnxnC(x)=\sum_{n\ge0}C_nx^n. The convolution Cn+1=iCiCniC_{n+1}=\sum_i C_iC_{n-i} says C(x)=1+xC(x)2C(x)=1+xC(x)^2. Solving the quadratic,

C(x)=114x2x,C(x)=\frac{1-\sqrt{1-4x}}{2x},

and expanding 14x\sqrt{1-4x} by the binomial series recovers Cn=1n+1(2nn)C_n=\frac1{n+1}\binom{2n}{n}. This “turn the recurrence into an equation for A(x)A(x), solve, expand” pipeline is the general method.

(C) Binet's formula for Fibonacci. The characteristic equation r2=r+1r^2=r+1 has roots φ=1+52\varphi=\frac{1+\sqrt5}{2} and ψ=152\psi=\frac{1-\sqrt5}{2}. Then

fn=φnψn5.f_n=\frac{\varphi^{\,n}-\psi^{\,n}}{\sqrt5}.

Since ψ<1|\psi|<1, fnf_n is the nearest integer to φn/5\varphi^{\,n}/\sqrt5, so Fibonacci numbers grow like φn\varphi^{\,n}.

Example
Worked example --- coefficients from 11xx2\dfrac{1}{1-x-x^2}

The Fibonacci GF is F(x)=fnxn=x1xx2F(x)=\sum f_nx^n=\dfrac{x}{1-x-x^2}. Factor the denominator using φ,ψ\varphi,\psi and split by partial fractions:

F(x)=15 ⁣(11φx11ψx)=15n0(φnψn)xn,F(x)=\frac{1}{\sqrt5}\!\left(\frac{1}{1-\varphi x}-\frac{1}{1-\psi x}\right) =\frac{1}{\sqrt5}\sum_{n\ge0}\bigl(\varphi^{\,n}-\psi^{\,n}\bigr)x^n,

which reads off Binet's formula directly. Partial fractions on 1/(1xx2)1/(1-x-x^2)-type denominators is the bridge from recurrence to closed form.

Tip

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 A(x)A(x) 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 ana_n; when you see “combine independent totals,” multiply GFs; when you see “non-crossing / balanced / never-behind,” reach for Catalan.

Nonhomogeneous & Higher-Order Linear Recurrences

Concept
Particular ++ homogeneous, with resonance

A linear recurrence with a forcing term,

an=c1an1++ckank+g(n),a_n=c_1a_{n-1}+\dots+c_ka_{n-k}+g(n),

is solved by

an  =  an(h)  +  an(p),a_n \;=\; a_n^{(h)} \;+\; a_n^{(p)},

where an(h)a_n^{(h)} is the general solution of the homogeneous part (characteristic roots, as before) and an(p)a_n^{(p)} is any one particular solution. To find an(p)a_n^{(p)}, guess a form matching g(n)g(n) and solve for its constants:

g(n)try an(p)=constantApolynomial of degree dAdnd++A1n+A0exponential bnAbn\begin{array}{c|c} g(n) & \text{try } a_n^{(p)}=\\\hline \text{constant} & A\\ \text{polynomial of degree } d & A_dn^d+\dots+A_1n+A_0\\ \text{exponential } b^{\,n} & A\,b^{\,n}\\ \end{array}

Resonance (the crucial trap). If your guess already solves the homogeneous equation --- e.g. g(n)=bng(n)=b^{\,n} but bb is a characteristic root, or g(n)g(n) is constant but r=1r=1 is a root --- multiply the guess by nn (by nmn^m if bb is a root of multiplicity mm). This is the same “multiply by nn for a repeated root” rule seen in the homogeneous case.

Example
Worked example --- a nonhomogeneous recurrence with resonance

Solve an=3an12an2+2na_n=3a_{n-1}-2a_{n-2}+2^{\,n} with a0=0, a1=0a_0=0,\ a_1=0.

Homogeneous part: r23r+2=(r1)(r2)=0r^2-3r+2=(r-1)(r-2)=0, so r=1,2r=1,2 and an(h)=α1n+β2na_n^{(h)}=\alpha\cdot1^{\,n}+\beta\cdot2^{\,n}.

Particular part: the natural guess A2nA\,2^{\,n} is resonant because r=2r=2 is already a root. Multiply by nn: try an(p)=An2na_n^{(p)}=A\,n\,2^{\,n}. Substituting,

An2n=3A(n1)2n12A(n2)2n2+2n.\begin{aligned} A n 2^{n} &= 3A(n-1)2^{n-1}-2A(n-2)2^{n-2}+2^{n}. \end{aligned}

Divide by 2n22^{n-2}: 4An=6A(n1)2A(n2)+44An = 6A(n-1)-2A(n-2)+4, i.e. 4An=4An2A+44An=4An-2A+4, giving A=2A=2. So an(p)=2n2n=n2n+1a_n^{(p)}=2n\,2^{\,n}=n\,2^{\,n+1}.

Combine and fit: an=α+β2n+n2n+1a_n=\alpha+\beta\,2^{\,n}+n\,2^{\,n+1}. From a0=α+β=0a_0=\alpha+\beta=0 and a1=α+2β+4=0a_1=\alpha+2\beta+4=0 we get β=4, α=4\beta=-4,\ \alpha=4. Thus

an=442n+n2n+1=42n+2+n2n+1.a_n=4-4\cdot2^{\,n}+n\,2^{\,n+1}=4-2^{\,n+2}+n\,2^{\,n+1}.

Check: a2=416+16=4a_2=4-16+16=4, and 3a12a0+22=00+4=43a_1-2a_0+2^2=0-0+4=4. ✓

Tip

Tips. (1) Always solve the homogeneous roots first --- you cannot detect resonance until you know them. (2) A constant forcing term with a root r=1r=1 needs the guess AnAn (not AA). (3) If g(n)g(n) is a sum of pieces, find a particular solution for each piece separately and add. (4) Fit the constants α,β\alpha,\beta using the full solution an(h)+an(p)a_n^{(h)}+a_n^{(p)}, never the homogeneous part alone.

The Transfer-Matrix Method

Concept
Recurrences as matrix powers

A coupled linear recurrence among finitely many states is one matrix TT acting on a state vector. If vn\mathbf{v}_n collects the state values at step nn and vn=Tvn1\mathbf{v}_n=T\mathbf{v}_{n-1}, then

vn=Tnv0.\mathbf{v}_n=T^{\,n}\mathbf{v}_0 .

For the Fibonacci recurrence, taking vn=[fn+1fn]\mathbf{v}_n=\begin{bmatrix}f_{n+1}\\ f_n\end{bmatrix},

[fn+1fn]=[1110][fnfn1],[fn+1fnfnfn1]=[1110]n.\begin{bmatrix}f_{n+1}\\ f_n\end{bmatrix} =\begin{bmatrix}1 & 1\\ 1 & 0\end{bmatrix} \begin{bmatrix}f_n\\ f_{n-1}\end{bmatrix}, \qquad \begin{bmatrix}f_{n+1} & f_n\\ f_n & f_{n-1}\end{bmatrix} =\begin{bmatrix}1 & 1\\ 1 & 0\end{bmatrix}^{\,n}.

The matrix's eigenvalues are exactly the characteristic roots φ,ψ\varphi,\psi, which is why TnT^{\,n} (hence every entry) is a combination of φn\varphi^{\,n} and ψn\psi^{\,n} --- another route to Binet's formula. Taking determinants of the boxed identity gives fn+1fn1fn2=(1)nf_{n+1}f_{n-1}-f_n^2=(-1)^n instantly (Cassini's identity).

Counting walks. If MM is the adjacency matrix of a (multi)graph, then (Mn)ij(M^{\,n})_{ij} counts walks of length nn from vertex ii to jj, and tr(Mn)=kλkn\operatorname{tr}(M^{\,n})=\sum_k\lambda_k^{\,n} counts closed walks. This packages “count paths through states” as matrix powers.

Example
Worked example --- walks on a triangle

Three vertices {1,2,3}\{1,2,3\} of a triangle are all mutually adjacent. How many closed walks of length nn start and end at vertex 11? The adjacency matrix is M=JIM=J-I where JJ is all-ones:

M=[011101110].M=\begin{bmatrix}0&1&1\\ 1&0&1\\ 1&1&0\end{bmatrix}.

Its eigenvalues: JJ has eigenvalues 3,0,03,0,0, so M=JIM=J-I has eigenvalues 2,1,12,-1,-1. By symmetry every diagonal entry of MnM^{\,n} is equal, and tr(Mn)=2n+2(1)n\operatorname{tr}(M^{\,n})=2^{\,n}+2(-1)^{\,n}, so

(Mn)11=2n+2(1)n3.(M^{\,n})_{11}=\frac{2^{\,n}+2(-1)^{\,n}}{3}.

Check n=2n=2: closed walks 1k11\to k\to1 number 22, and 4+23=2\tfrac{4+2}{3}=2. ✓ For n=3n=3 we get 823=2\tfrac{8-2}{3}=2, the two directed triangles 12311\to2\to3\to1 and 13211\to3\to2\to1. This is the standard AIME-style “ant walks on a solid/graph and returns home” setup.

Tip

Tips. (1) Order-kk scalar recurrences become k×kk\times k companion matrices whose characteristic polynomial is the recurrence's. (2) For symmetric transition structures, diagonalizing via eigenvalues turns TnT^{\,n} into a clean closed form --- look for an all-ones or circulant pattern. (3) tr(Mn)=λn\operatorname{tr}(M^{\,n})=\sum\lambda^{\,n} and det\det 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

Concept
Rotation counting and the general ballot theorem

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 nn steps that are +1+1's and 1-1's summing to +1+1 (so n+12\frac{n+1}{2} ups and n12\frac{n-1}{2} downs). Among its nn cyclic rotations, exactly one has all partial sums strictly positive.

Ballot Theorem. In an election where AA gets aa votes and BB gets b<ab<a votes, the number of orderings of the ballots in which AA is strictly ahead throughout is

aba+b(a+ba).\frac{a-b}{a+b}\binom{a+b}{a}.

Catalan is the boundary case: paths from (0,0)(0,0) to (n,n)(n,n) staying strictly below the diagonal except at the ends correspond to a=n+1, b=na=n+1,\ b=n shifted, and the ballot formula collapses to Cn=1n+1(2nn)C_n=\frac{1}{n+1}\binom{2n}{n}.

Example
Worked example --- counting good arrangements by rotation

In how many ways can n+1n+1 people holding a $5 bill and nn people holding a $10 bill line up at a box office charging $5, starting with an empty till, so the cashier can always give change?

Model each $5 as +1+1 and each $10 as 1-1. There are 2n+12n+1 people; the partial sums must stay 0\ge 0 (in fact >0>0 after the first person once we require never getting stuck), and the total is (n+1)n=+1(n+1)-n=+1. Any arrangement of the 2n+12n+1 steps summing to +1+1 has, by the cycle lemma, exactly one of its 2n+12n+1 rotations with all partial sums positive. Since the total number of step-sequences is (2n+1n)\binom{2n+1}{n} and they group into rotation-classes each contributing exactly one good sequence,

#{good lines}=12n+1(2n+1n)=Cn.\#\{\text{good lines}\}=\frac{1}{2n+1}\binom{2n+1}{n}=C_n .

For n=2n=2 ($5,$5,$5 and $10,$10): 15(52)=2=C2\frac{1}{5}\binom{5}{2}=2=C_2. ✓ The one-good-rotation-per-class argument avoids any reflection bijection entirely.

Tip

Tips. (1) The cycle lemma also proves the Fuss--Catalan numbers 1kn+1(kn+1n)\frac{1}{kn+1}\binom{kn+1}{n} (paths with up-steps +1+1 and down-steps (k1)-(k-1)) --- 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

Concept
EGFs for labeled structures

When objects are built on labeled elements (people, positions 1..n1..n that are distinguishable), the right bookkeeping tool is the exponential generating function

A^(x)=n0anxnn!.\widehat{A}(x)=\sum_{n\ge0}a_n\frac{x^n}{n!}.

The key rule mirrors the ordinary case but with a binomial-flavored product:

A^(x)B^(x)=n0(k(nk)akbnk)xnn!.\widehat{A}(x)\,\widehat{B}(x)=\sum_{n\ge0}\left(\sum_{k}\binom{n}{k}a_k\,b_{n-k}\right)\frac{x^n}{n!}.

The (nk)\binom{n}{k} appears because you first choose which labels go to the AA-part. Building blocks:

ex=n0xnn! (one labeled set),11x=n0n!xnn! (a linear order).e^{x}=\sum_{n\ge0}\frac{x^n}{n!}\ (\text{one labeled set}),\qquad \frac{1}{1-x}=\sum_{n\ge0}n!\,\frac{x^n}{n!}\ (\text{a linear order}).

The Exponential Formula A^(x)=eC^(x)\widehat{A}(x)=e^{\widehat{C}(x)} passes from “connected” pieces C^\widehat{C} to arbitrary disjoint unions of them (set partitions into blocks, permutations into cycles, graphs into components).

Example
Worked example --- derangements via an EGF

A derangement is a permutation with no fixed point; let DnD_n be their count. Every permutation splits its nn labels into a set of fixed points and a derangement of the rest:

n!=k=0n(nk)Dnk1.n!=\sum_{k=0}^{n}\binom{n}{k}D_{n-k}\cdot 1 .

In EGF language this is a product: (all permutations) == (choose fixed points) ×\times (derange the rest), i.e.

11x=exD^(x)D^(x)=ex1x.\frac{1}{1-x}=e^{x}\cdot \widehat{D}(x) \quad\Longrightarrow\quad \widehat{D}(x)=\frac{e^{-x}}{1-x}.

Reading off the coefficient of xn/n!x^n/n!,

Dn=n!k=0n(1)kk!,D_n=n!\sum_{k=0}^{n}\frac{(-1)^k}{k!},

the familiar inclusion--exclusion formula, and DnD_n is the nearest integer to n!/en!/e. From D^(x)=ex/(1x)\widehat{D}(x)=e^{-x}/(1-x) one also reads the recurrences Dn=nDn1+(1)nD_n=nD_{n-1}+(-1)^n and Dn=(n1)(Dn1+Dn2)D_n=(n-1)(D_{n-1}+D_{n-2}).

Tip

Big picture. Use an ordinary GF anxn\sum a_nx^n when parts combine by “split the total” (unlabeled: coins, compositions, tilings); use an exponential GF anxn/n!\sum a_n x^n/n! when parts combine by “distribute distinct labels” (labeled: permutations, set partitions, surjections). The dictionary --- product == independent combination, eC^=e^{\widehat{C}}= disjoint components --- lets you write the answer's generating function directly from a structural description, then extract ana_n by expanding.

Formulas, Proofs & Tips

Tip
Recursions and Catalan numbers
an=an1+an2 (Fibonacci),Cn=1n+1(2nn)a_n=a_{n-1}+a_{n-2} \ (\text{Fibonacci}),\qquad C_n=\frac{1}{n+1}\binom{2n}{n}

What it means. Define a term from earlier terms; Catalan numbers count balanced structures.

Example. Fibonacci: 1,1,2,3,5,8,1,1,2,3,5,8,\dots; and C3=14(63)=5C_3=\tfrac14\binom63=5.

Why it works. Fibonacci-style counts split on the last step: a tiling ending in a single square leaves an1a_{n-1} ways, one ending in a domino leaves an2a_{n-2}, and the cases do not overlap. Catalan counts paths that never dip below the axis — the reflection argument removes exactly (2nn+1)\binom{2n}{n+1} bad paths.

Tip. Always state the base cases; a recursion without them defines nothing.