Overview

Advanced counting often uses bijections or recursive structure. The goal is to rephrase the problem into a simpler counting model.

Recursion is especially powerful for tilings, strings with restrictions, and state-based counting processes.

Key Ideas

  • Bijection: count a set by mapping it to another set of known size.
  • Recursion: count size nn objects by splitting into smaller sizes.
  • Invariants help track what must remain constant across transformations.
  • Characteristic equations solve linear recurrences.

Core Skills

Build a State Recurrence

Define states by the last few choices and build a recurrence with transitions.

Use Inclusion-Exclusion Carefully

When constraints overlap, compute total minus overlaps instead of ad hoc casework.

Identify a Bijection

Map objects to lattice paths or subsets to simplify the count.

Worked Example

Let ana_n be the number of binary strings of length nn with no consecutive 11's. Then an=an−1+an−2a_n=a_{n-1}+a_{n-2} by considering the last digit. This is Fibonacci.

More Examples

Example 1: Tilings

Let f(n)f(n) be the number of tilings of a 2×n2\times n board with dominoes. f(n)=f(n−1)+f(n−2)f(n)=f(n-1)+f(n-2) with f(1)=1f(1)=1, f(2)=2f(2)=2.

Example 2: Inclusion-Exclusion

How many permutations of {1,2,3,4}\{1,2,3,4\} have no fixed points?

!4=4!(1−1+1/2−1/6+1/24)=9!4=4!(1-1+1/2-1/6+1/24)=9.

Example 3: Bijection

Count binary strings of length nn with no consecutive 11's.

Map them to tilings of a 1×n1\times n board with squares and dominoes.

Strategy Checklist

  • Define states clearly for recurrences.
  • Look for bijections to standard models.
  • Use inclusion-exclusion for overlapping constraints.

Common Pitfalls

  • Double-counting when states are not disjoint.
  • Forgetting initial conditions in recurrences.
  • Applying inclusion-exclusion without checking overlaps.

Recursion Patterns

Tilings

For a 2×n2\times n board tiled by dominoes, the final placement is vertical or two horizontals, giving f(n)=f(n−1)+f(n−2)f(n)=f(n-1)+f(n-2).

Strings with Constraints

If a string must avoid a pattern, classify by the last few characters to build states. Each state contributes a recurrence.

Linear Recurrences

If f(n)=c1f(n−1)+c2f(n−2)f(n)=c_1 f(n-1)+c_2 f(n-2), solve r2−c1r−c2=0r^2-c_1 r-c_2=0. Then f(n)=Ar1n+Br2nf(n)=A r_1^n + B r_2^n with constants from base cases.

Example 1: Explicit Recurrence

Suppose f(n)=2f(n−1)−2nf(n)=2f(n-1)-2^n with f(0)=5f(0)=5. The homogeneous solution is C⋅2nC\cdot 2^n. A particular solution is −n⋅2n-n\cdot 2^n. So f(n)=(5−n)2nf(n)=(5-n)2^n.

Example 2: Catalan Bijections

Problem. How many permutations of 1,2,…,n{1,2,\ldots,n} have no three (not necessarily consecutive) entries in decreasing order from left to right? For example, 154623154623 is an example of such a permutation, while 254713254713 is not, because of 541541.

Solution. We split the permutation into blocks according to its left-to-right maxima. A left-to-right maximum is a number that is larger than everything before it.

For example, in the permutation

1263745,1263745,

the left-to-right maxima are

1,2,6,7.1,2,6,7.

So we split the permutation right before each new left-to-right maximum:

(1)(2)(63)(745).(1)(2)(63)(745).

Each block starts with its maximum. In this example, the block maxima are

1,2,6,7.1,2,6,7.

Now the key observation is that in a 321321-avoiding permutation, all the numbers that are not left-to-right maxima must appear in increasing order.

For example,

(1)(2)(63)(745)(1)(2)(63)(745)

has non-left-to-right maxima

3,4,5,3,4,5,

which are increasing.

Why must this happen? Suppose two non-left-to-right maxima appeared in decreasing order, say

a>b.a>b.

Since aa is not a left-to-right maximum, there is some earlier number larger than aa. Then we would have

earlier larger number>a>b,\text{earlier larger number} > a > b,

which forms a 321321 pattern.

For example, the permutation

2531425314

does not work. The numbers 33 and 11 are non-left-to-right maxima, and they appear in decreasing order. Since 55 comes before them and is larger than both, we get

5>3>1,5>3>1,

which is a 321321 pattern.

So in a 321321-avoiding permutation, once we know the left-to-right maxima and the sizes of the blocks, the rest of the permutation is forced.

For example, suppose n=7n=7, the block maxima are

1,2,6,7,1,2,6,7,

and the block sizes are

1,1,2,3.1,1,2,3.

Then the blocks must look like

(1)(2)(6_)(7__).(1)(2)(6\_)(7\_\_).

The remaining numbers are

3,4,5.3,4,5.

They must be placed in increasing order, so the only possible permutation is

(1)(2)(63)(745).(1)(2)(63)(745).

As another example, suppose n=6n=6, the block maxima are

2,5,6,2,5,6,

and the block sizes are

2,3,1.2,3,1.

Then the blocks must look like

(2_)(5__)(6).(2\_)(5\_\_)(6).

The remaining numbers are

1,3,4.1,3,4.

They must go in increasing order, giving

(21)(534)(6).(21)(534)(6).

Now we connect this to Catalan paths. Let the block maxima be

m1,m2,…,mkm_1,m_2,\ldots,m_k

and let

pi=∣b1∣+∣b2∣+⋯+∣bi∣p_i=|b_1|+|b_2|+\cdots+|b_i|

be the ending position of the iith block.

For example, in

(1)(2)(63)(745),(1)(2)(63)(745),

we have

m1,m2,m3,m4=1,2,6,7m_1,m_2,m_3,m_4=1,2,6,7

and the block ending positions are

p1,p2,p3,p4=1,2,4,7.p_1,p_2,p_3,p_4=1,2,4,7.

So we get the points

(1,1),(2,2),(6,4),(7,7).(1,1),(2,2),(6,4),(7,7).

These points all satisfy

pi≤mi,p_i \le m_i,

because among the first pip_i positions, all numbers must be at most mim_i. This means the corresponding path stays on or below the diagonal y=xy=x.

Thus, each 321321-avoiding permutation gives a path from (0,0)(0,0) to (n,n)(n,n) that never goes above the diagonal.

Conversely, given a Catalan path, we can read off the block maxima and block sizes from its corner points. Then we fill in all non-left-to-right maxima in increasing order. Since the filling is forced, this gives exactly one 321321-avoiding permutation.

Therefore, the number of 321321-avoiding permutations of

{1,2,…,n}\lbrace 1,2,\ldots,n \rbrace

is the Catalan number

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

For example, if n=3n=3, the answer is

C3=14(63)=5.C_3=\frac{1}{4}\binom{6}{3}=5.

Indeed, the 321321-avoiding permutations are

123,132,213,231,312.123,132,213,231,312.

The only permutation that does not work is

321.321.

If n=6n=6, the answer is

C6=17(126)=9247=132.C_6=\frac{1}{7}\binom{12}{6} =\frac{924}{7} =\mathbf{132}.

Practice Problems

StatusSourceProblem NameDifficultyTags
AIMEVery Hard
Show TagsCombinatorics, Recursion
AIMEVery Hard
Show TagsBijection
Berkeley Math Circle Monthly Contest 7Hard
Show TagsCounting two ways, Recursion, bijection
Berkeley Math Circle Monthly Contest 5Hard
Show Tags3D Shapes, Counting two ways
Berkeley Math Circle Monthly Contest 4Hard
Show TagsCounting two ways
Berkeley Math Circle Take-Home Contest #2Hard
Show TagsCounting two ways, Invariants / monovariants
Berkeley Math CircleHard
Show TagsCounting two ways, Graph Theory, Invariants / monovariants
Berkeley Math CircleHard
Show TagsCounting two ways, Recursion, bijection
Berkeley Math Circle Monthly Contest 2Hard
Show TagsCounting two ways, Sums and products
Berkeley Math Circle Monthly Contest 6Hard
Show TagsCounting two ways, Enumeration with symmetry
Berkeley Math CircleHard
Show TagsCounting two ways, Recursion, bijection
Berkeley Math Circle Monthly Contest 4Hard
Show TagsCounting two ways, Invariants / monovariants
Berkeley Math CircleHard
Show TagsCounting two ways, Factorization techniques, τ (number of divisors)
MathNetHard
Show TagsCounting two ways, Graph Theory, Invariants / monovariants
Berkeley Math Circle Monthly Contest 5Hard
Show TagsAngle chasing, Counting two ways
Berkeley Math Circle: Monthly Contest 7Hard
Show TagsCounting two ways, Invariants / monovariants, Sums and products
Berkeley Math CircleHard
Show TagsCauchy-Schwarz, Counting two ways
Berkeley Math CircleHard
Show TagsColoring schemes, extremal arguments, Constructions and loci, Counting two ways
Berkeley Math Circle Monthly Contest 7Hard
Show TagsCounting two ways, Invariants / monovariants
Berkeley Math CircleHard
Show TagsColoring schemes, extremal arguments, Counting two ways, Floors and ceilings, Invariants / monovariants, Linear and quadratic inequalities
Berkeley Math CircleHard
Show TagsColoring schemes, extremal arguments, Counting two ways
Berkeley Math Circle Monthly Contest 6Hard
Show TagsCounting two ways, Pigeonhole principle
Berkeley Math Circle Monthly Contest 4Hard
Show TagsCounting two ways, Floors and ceilings, φ (Euler's totient)
Berkeley Math Circle: Monthly Contest 6Hard
Show TagsCounting two ways, Enumeration with symmetry
Berkeley Math Circle Monthly Contest 6Hard
Show TagsCounting two ways, Recursion, bijection

Module Progress:

Join the Discord Community!

Stuck on a problem, or don't understand a module? Join the Discord and get help with your doubts while making more math friends.