Discrete MathematicsBinomial Coefficients and Pascal's Triangle4 of 4
Binomial Coefficients and Pascal's Triangle · 4

Block Walking, Lattice Paths and Catalan Numbers

We need to count how many shortest paths lead from one corner of a street grid to another, both when the grid is wide open and when roadblocks or boundary lines get in the way.

1

Adding Corners and Routing Around Roadblocks

On a 4×34 \times 3 grid from (0,0)(0,0) to (4,3)(4,3), a shortest path only steps Right and Up. Tracing routes one by one gets messy fast, so instead we count how many paths reach each intersection from the two corners that lead directly into it.

Adding Corners and Routing Around Roadblocks
Start\text{Start}
End\text{End}
44
33
Text solution
Fill the starting edges with 1\pathcount{1}'sEvery corner along the bottom edge and the left edge can only be reached by walking straight along that edge, so each one gets 1\pathcount{1} path.
Add the corner to the left and the corner belowEvery inside corner (x,y)(x,y) is entered either from (x−1,y)(x-1,y) on its left or from (x,y−1)(x,y-1) below it, reaching 35\pathcount{35} paths at (4,3)(4,3).
paths to (x,y)=paths to (x−1,y)+paths to (x,y−1)paths to (4,3)=20+15=35\displaystyle \begin{aligned} &\text{paths to }(x,y) \\ &\quad = \text{paths to }(x-1,y) \\ &\qquad + \text{paths to }(x,y-1) \\ &\text{paths to }(4,3) \\ &\quad = 20 + 15 = \pathcount{35} \end{aligned}
Set a blocked corner to 0\fails{0} and keep addingWhen (2,2)\fails{(2,2)} is closed for construction, no path can pass through it, so we write 0\fails{0} at (2,2)\fails{(2,2)} and recompute the corners above it and to its right.
paths to (2,2)=0paths to (2,3)=4+0=4,paths to (3,2)=0+4=4paths to (3,3)=4+4=8,paths to (4,2)=4+5=9paths to (4,3)=8+9=17\displaystyle \begin{aligned} \text{paths to }\fails{(2,2)} &= \fails{0} \\ \text{paths to }(2,3) &= 4 + \fails{0} = 4, \\ \text{paths to }(3,2) &= \fails{0} + 4 = 4 \\ \text{paths to }(3,3) &= 4 + 4 = 8, \\ \text{paths to }(4,2) &= 4 + 5 = 9 \\ \text{paths to }(4,3) &= 8 + 9 = \pathcount{17} \end{aligned}

So closing the single intersection (2,2)\fails{(2,2)} cuts the number of shortest paths from 35\pathcount{35} down to 17\pathcount{17}.

1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
2\htmlClass{lc-green}{2}
3\htmlClass{lc-green}{3}
4\htmlClass{lc-green}{4}
5\htmlClass{lc-green}{5}
1\htmlClass{lc-green}{1}
3\htmlClass{lc-green}{3}
6\htmlClass{lc-green}{6}
10\htmlClass{lc-green}{10}
15\htmlClass{lc-green}{15}
1\htmlClass{lc-green}{1}
4\htmlClass{lc-green}{4}
10\htmlClass{lc-green}{10}
20\htmlClass{lc-green}{20}
35\htmlClass{lc-green}{35}
Start\text{Start}
End\text{End}
all corners open\text{all corners open}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
2\htmlClass{lc-green}{2}
3\htmlClass{lc-green}{3}
4\htmlClass{lc-green}{4}
5\htmlClass{lc-green}{5}
1\htmlClass{lc-green}{1}
3\htmlClass{lc-green}{3}
0\htmlClass{lc-orange}{0}
4\htmlClass{lc-green}{4}
9\htmlClass{lc-green}{9}
1\htmlClass{lc-green}{1}
4\htmlClass{lc-green}{4}
4\htmlClass{lc-green}{4}
8\htmlClass{lc-green}{8}
17\htmlClass{lc-green}{17}
Start\text{Start}
End\text{End}
(2,2) closed\htmlClass{lc-orange}{(2,2)}\text{ closed}

Setting a blocked corner to 0\fails{0} only changes the counts at intersections above it and to its right, and blocking a central intersection cuts the total at (4,3)(4,3) far more than blocking a far corner like (0,3)\fails{(0,3)} or (4,0)\fails{(4,0)}, which only 1\pathcount{1} path ever reaches.

A roadblock sets its own corner to zero and only changes the corners above and to its right, which still add the corners to their left and below.
2

Grid Paths as Words of R's and U's

Adding corner by corner handles roadblocks easily, but on a large open grid we want to find the total number of paths from (0,0)(0,0) to (m,n)(m,n) without filling in every intersection. We can do that by writing each path as a word made of steps Right (R\text{R}) and steps Up (U\text{U}).

Grid Paths as Words of R's and U's
Start\text{Start}
End\text{End}
paths=  ?\text{paths} = \;?
Text solution
Choose which slots get a U\text{U} on the 4×34 \times 3 gridEvery path from (0,0)(0,0) to (4,3)(4,3) is a 77-letter word with 44 R\text{R}'s and 33 U\text{U}'s, which is completely set once we pick which 33 of the 77 slots hold a U\text{U}.
C(7,3)\displaystyle C(7,3) =7!3! 4!\displaystyle = \frac{7!}{3!\,4!} =7×6×53×2×1\displaystyle = \frac{7 \times 6 \times 5}{3 \times 2 \times 1} =35\displaystyle = \pathcount{35}
Split the walk at the (3,2)(3,2) checkpointA path from (0,0)(0,0) to (7,5)(7,5) that passes through (3,2)(3,2) walks 3\firstleg{3} blocks Right and 2\firstleg{2} blocks Up to reach (3,2)(3,2), and then 7−3=47 - 3 = \secondleg{4} blocks Right and 5−2=35 - 2 = \secondleg{3} blocks Up from (3,2)(3,2) to (7,5)(7,5).
Start to (3,2)=C(3+2,2)=C(5,2)=10(3,2) to (7,5)=C(4+3,3)=C(7,3)=35Total pathsthrough (3,2)=10×35=350\displaystyle \begin{aligned} \firstleg{\text{Start to }(3,2)} &= C(3+2, 2) \\ &= C(5,2) = \firstleg{10} \\ \secondleg{(3,2)\text{ to }(7,5)} &= C(4+3, 3) \\ &= C(7,3) = \secondleg{35} \\ \text{Total paths} & \\ \text{through }(3,2) &= \firstleg{10} \times \secondleg{35} = \pathcount{350} \end{aligned}

So 350\pathcount{350} shortest paths from (0,0)(0,0) to (7,5)(7,5) pass through the coffee shop at (3,2)(3,2).

On any open grid from (0,0)(0,0) to (m,n)(m,n), every path takes m+nm + n steps in total and chooses nn of them to go Up (or mm of them to go Right):

paths from (0,0) to (m,n)\displaystyle \text{paths from }(0,0)\text{ to }(m,n) =C(m+n⏟total steps,n⏟steps Up)\displaystyle = C(\underbrace{m+n}_{\text{total steps}}, \underbrace{n}_{\text{steps Up}}) =C(m+n,m)\displaystyle = C(m+n, m)
3

Counting Paths Two Ways

Now we want to prove that the sum of the squares of row nn of Pascal's triangle equals C(2n,n)C(2n,n):

C(n,0)2+C(n,1)2+C(n,2)2+⋯+C(n,n)2\displaystyle C(n,0)^2 + C(n,1)^2 + C(n,2)^2 + \dots + C(n,n)^2 =C(2n,n)\displaystyle = C(2n,n)

Instead of expanding factorials with algebra, we count the shortest paths from (0,0)(0,0) to (n,n)(n,n) in two ways: all at once, and split along the halfway line after nn steps.

Counting Paths Two Ways
(0,0)(0,0)
(4,4)(4,4)
Way 1=  ?Way 2=  ?\begin{aligned}\text{Way 1} &= \;?\\ \text{Way 2} &= \;?\end{aligned}
(4,0)(4,0)
(3,1)(3,1)
(2,2)(2,2)
(1,3)(1,3)
(0,4)(0,4)
(0,0)(0,0)
(4,4)(4,4)
first 4 steps\htmlClass{lc-blue}{\text{first }4\text{ steps}}
last 4 steps\htmlClass{lc-pink}{\text{last }4\text{ steps}}
Text solution
Way 1: Count all paths to (4,4)(4,4) at onceEvery path takes 88 steps total and chooses 44 of them to go Up.
C(8,4)\displaystyle C(8,4) =8×7×6×54×3×2×1\displaystyle = \frac{8 \times 7 \times 6 \times 5}{4 \times 3 \times 2 \times 1} =70\displaystyle = \pathcount{70}
Way 2: Count paths through the halfway corner (4−k,k)(4-k, k)After 44 steps, a path that has taken k\firstleg{k} steps Up and 4−k\firstleg{4 - k} steps Right still needs 4−(4−k)=k4 - (4 - k) = \secondleg{k} steps Right during its last 44 steps to reach (4,4)(4,4).
C(4,k)⏟first 4 steps (choose k U’s)×C(4,k)⏟last 4 steps (choose k R’s)\displaystyle \firstleg{\underbrace{C(4,k)}_{\text{first }4\text{ steps (choose }k\text{ U's)}}} \times \secondleg{\underbrace{C(4,k)}_{\text{last }4\text{ steps (choose }k\text{ R's)}}} =C(4,k)2\displaystyle = C(4,k)^2
Add across all five halfway cornersBecause every 88-step path is at (4−k,k)(4-k, k) for exactly one k∈{0,1,2,3,4}k \in \{0, 1, 2, 3, 4\} after its 44th step, summing the five cases gives the same 70\pathcount{70} paths.
C(4,0)2+C(4,1)2+C(4,2)2+C(4,3)2+C(4,4)2=C(8,4)12+42+62+42+12=70\displaystyle \begin{aligned} C(4,0)^2 + C(4,1)^2 & \\ {} + C(4,2)^2 + C(4,3)^2 & \\ {} + C(4,4)^2 &= C(8,4) \\ 1^2 + 4^2 + 6^2 + 4^2 + 1^2 &= \pathcount{70} \end{aligned}

On an n×nn \times n grid, splitting every 2n2n-step walk after its first nn steps proves C(n,0)2+C(n,1)2+⋯+C(n,n)2C(n,0)^2 + C(n,1)^2 + \dots + C(n,n)^2 == C(2n,n)C(2n,n).

4

Staying Below the Diagonal and the Catalan Numbers

Next, we stay on the square grid from (0,0)(0,0) to (n,n)(n,n) and add a boundary rule: we want to count how many paths never cross above the main diagonal y=xy = x.

Staying Below the Diagonal and the Catalan Numbers
(0,0)(0,0)
(4,4)(4,4)
paths never above the diagonal=  ?\text{paths never above the diagonal} = \;?
Text solution
Erase the corners above y=xy = x and add corner by cornerBecause no path can step above the diagonal, every diagonal corner (k,k)(k,k) can only be reached from (k,k−1)(k, k-1) directly below it, carrying that count straight up.
C0=1 at (0,0),C1=1 at (1,1),C2=2 at (2,2)C3=5 at (3,3),C4=14 at (4,4),C5=42 at (5,5)\displaystyle \begin{aligned} C_0 &= \pathcount{1} &&\text{ at }(0,0), \\ C_1 &= \pathcount{1} &&\text{ at }(1,1), \\ C_2 &= \pathcount{2} &&\text{ at }(2,2) \\ C_3 &= \pathcount{5} &&\text{ at }(3,3), \\ C_4 &= \pathcount{14} &&\text{ at }(4,4), \\ C_5 &= \pathcount{42} &&\text{ at }(5,5) \end{aligned}
Translate the diagonal rule into R\text{R}'s and U\text{U}'sStepping above y=xy = x means taking more U\text{U}'s than R\text{R}'s, so staying on or below the diagonal means that at every point from left to right:
number of R’s so far\displaystyle \text{number of R's so far} ≥number of U’s so far\displaystyle \ge \text{number of U's so far}

So 44 opening brackets `(` and 44 closing brackets `)` can be properly nested in C4=14C_4 = \pathcount{14} ways, and 44 customers with $5\$5 bills (R\text{R}) and 44 customers with $10\$10 bills (U\text{U}) can line up at an empty register in 14\pathcount{14} different orders of bills without the cashier running out of change.

In this 4×44 \times 4 walk, the path crosses above the diagonal y=xy = x in red at the exact character where the number of closing brackets read from the left first goes past the number of opening brackets.

A walk of four R's and four U's crosses above the diagonal at the exact bracket where closing brackets outnumber the opening brackets read so far.
5

The Reflection Method

Adding corners up the grid found C4=14C_4 = \pathcount{14}, but for a larger grid we want a direct combinations formula for the nnth Catalan number CnC_n. Instead of counting the good paths directly, we count the bad paths (the ones that cross above y=xy = x and touch the red forbidden line y=x+1\redline{y = x + 1}) and subtract them from the total paths C(2n,n)C(2n,n).

The Reflection Method
(0,0)(0,0)
(4,4)(4,4)
70=good+badgood=  ?\begin{aligned}70 &= \htmlClass{lc-green}{\text{good}} + \htmlClass{lc-orange}{\text{bad}}\\ \htmlClass{lc-green}{\text{good}} &= \;?\end{aligned}
Text solution
Count all paths to (4,4)(4,4) without the boundaryAny choice of 44 R\text{R}'s out of 88 steps gives a path.
Total paths\displaystyle \text{Total paths} =C(8,4)\displaystyle = C(8,4) =70\displaystyle = 70
Flip every bad path after its first touch on the red line y=x+1\redline{y = x + 1}At the first corner where a bad path touches y=x+1\redline{y = x + 1}, it has taken 11 more U\text{U} than R\text{R}, so swapping every remaining R\text{R} and U\text{U} turns its 44 R\text{R}'s and 44 U\text{U}'s into 3\fails{3} R\text{R}'s and 5\fails{5} U\text{U}'s, matching bad paths to (4,4)(4,4) one-to-one with all paths to (3,5)\fails{(3,5)}.
Bad paths\displaystyle \text{Bad paths} =C(8,3)\displaystyle = \fails{C(8,3)} =8×7×63×2×1\displaystyle = \frac{8 \times 7 \times 6}{3 \times 2 \times 1} =56\displaystyle = \fails{56}
Subtract bad paths from total pathsRemoving the 56\fails{56} bad paths leaves the 14\pathcount{14} good paths that never cross above y=xy = x.
C4\displaystyle C_4 =C(8,4)−C(8,3)\displaystyle = C(8,4) - \fails{C(8,3)} =70−56\displaystyle = 70 - \fails{56} =14\displaystyle = \pathcount{14}

On any n×nn \times n grid, reflecting (n,n)(n,n) across y=x+1\redline{y = x + 1} lands at (n−1,n+1)\fails{(n-1, n+1)}. Since C(2n,n−1)\fails{C(2n,n-1)} == (2n)!(n−1)! (n+1)!\frac{(2n)!}{(n-1)!\,(n+1)!} == nn+1C(2n,n)\fails{\frac{n}{n+1}}C(2n,n), the bad paths are always nn+1\fails{\frac{n}{n+1}} of the total (for n=4n = 4, 56\fails{56} is 45\fails{\frac45} of 7070), and the good paths are the 1n+1\pathcount{\frac{1}{n+1}} that's left (for n=4n = 4, 15\pathcount{\frac15} of 7070 is 14\pathcount{14}). That gives the formula for the nnth Catalan number:

Cn\displaystyle C_n =C(2n,n)⏟total paths to (n,n)−C(2n,n−1)⏟bad paths, reflected to (n−1,n+1)\displaystyle = \underbrace{C(2n,n)}_{\text{total paths to }(n,n)} - \fails{\underbrace{C(2n,n-1)}_{\text{bad paths, reflected to }(n-1, n+1)}} =1n+1C(2n,n)\displaystyle = \pathcount{\frac{1}{n+1}}C(2n,n)

No matter which bad path you take from (0,0)(0,0) to (4,4)(4,4) or where its red dot first touches the forbidden line y=x+1\redline{y = x + 1}, flipping every R\text{R} and U\text{U} after that dot always sends the orange reflected tail to the exact same corner, (3,5)\fails{(3,5)}.

Interactive c3
6

Reflecting on Rectangular Grids and Shifted Boundaries

The Catalan formula CnC_n only applies when you have an equal number of R\text{R}'s and U\text{U}'s and the forbidden line is y=x+1\redline{y = x + 1}. Now we want to count valid paths when there are more R\text{R}'s than U\text{U}'s (a rectangular walk from (0,0)(0,0) to (6,3)(6,3)) or when the register starts with $5\$5 bills already inside (which shifts the red forbidden line up).

Reflecting on Rectangular Grids and Shifted Boundaries
55
55
55
55
55
55
1010
1010
1010
(0,0)(0,0)
(6,3)(6,3)
y=xy = x
y=x+1\htmlClass{lc-pink}{y = x + 1}
y=xy = x
y=x+1\htmlClass{lc-pink}{y = x + 1}
y=x+2\htmlClass{lc-pink}{y = x + 2}
(0,0)(0,0)
(6,3)(6,3)
(3,6)\htmlClass{lc-violet}{(3,6)}
(2,7)\htmlClass{lc-orange}{(2,7)}
(1,8)\htmlClass{lc-orange}{(1,8)}
Text solution
Empty register on a 6×36 \times 3 grid (forbidden line y=x+1\redline{y = x + 1})Swapping (6,3)(6,3) across y=xy = x gives (3,6)\swapped{(3,6)}, and shifting 11 step left and 11 step up for y=x+1\redline{y = x + 1} lands every reflected bad path at (2,7)\fails{(2,7)}.
Total paths to (6,3)=C(9,3)=84Bad paths (to (2,7))=C(9,2)=36Good paths=84−36=48\displaystyle \begin{aligned} \text{Total paths to }(6,3) &= C(9,3) \\ &= 84 \\ \text{Bad paths (to }\fails{(2,7)}\text{)} &= \fails{C(9,2)} \\ &= \fails{36} \\ \text{Good paths} &= 84 - \fails{36} \\ &= \pathcount{48} \end{aligned}
One starter $5\$5 bill on a 6×36 \times 3 grid (forbidden line y=x+2\redline{y = x + 2})With one $5\$5 bill already in the drawer, the cashier only runs out of change when a path reaches 22 more U\text{U}'s than R\text{R}'s, shifting the red forbidden line to y=x+2\redline{y = x + 2} and shifting (3,6)\swapped{(3,6)} by 22 steps left and 22 steps up to (1,8)\fails{(1,8)}.
Bad paths (to (1,8))=C(9,1)=9Good paths=84−9=75\displaystyle \begin{aligned} \text{Bad paths (to }\fails{(1,8)}\text{)} &= \fails{C(9,1)} \\ &= \fails{9} \\ \text{Good paths} &= 84 - \fails{9} \\ &= \pathcount{75} \end{aligned}

So starting with one $5\$5 bill in the register raises the number of valid orders of bills from 48\pathcount{48} to 75\pathcount{75}. In general, if you start with ss starter supplies, you only run out when U\text{U}'s go past R\text{R}'s by c=s+1c = s + 1, putting the forbidden line at y=x+c\redline{y = x + c}.

7

The Catalan Recurrence

Some counting problems produce the Catalan numbers 1,1,2,5,14,42\pathcount{1, 1, 2, 5, 14, 42} even when there isn't a grid walk in sight. To recognize them, we find how each Catalan number CnC_n is built out of the earlier ones by grouping the valid paths from (0,0)(0,0) to (n,n)(n,n) according to the corner (k,k)(k,k) where they touch the diagonal y=xy = x for the very first time after leaving (0,0)(0,0).

The Catalan Recurrence
(    or    )(\;\;{\small\text{or}}\;\;)
55
or\text{or}
1010
R    or    U\text{R}\;\;{\small\text{or}}\;\;\text{U}
1,\htmlClass{lc-green}{1,}
1,\htmlClass{lc-green}{1,}
2,\htmlClass{lc-green}{2,}
5,\htmlClass{lc-green}{5,}
14,\htmlClass{lc-green}{14,}
42\htmlClass{lc-green}{42}
??
Text solution
Count the walk up to the first return at (k,k)(k,k)Because the path cannot touch y=xy = x before (k,k)(k,k), its first step must go Right to (1,0)(1,0) and its step into (k,k)(k,k) must come Up from (k,k−1)(k, k-1), leaving a (k−1)×(k−1)\firstleg{(k-1) \times (k-1)} Catalan walk between (1,0)(1,0) and (k,k−1)(k, k-1) in Ck−1\firstleg{C_{k-1}} ways.
Multiply by the remaining walk from (k,k)(k,k) to (4,4)(4,4)From (k,k)(k,k) to (4,4)(4,4) is an ordinary (4−k)×(4−k)\secondleg{(4-k) \times (4-k)} Catalan walk in C4−k\secondleg{C_{4-k}} ways, giving Ck−1C4−k\firstleg{C_{k-1}} \secondleg{C_{4-k}} paths whose first return to the diagonal is at (k,k)(k,k).
Add across all four first-return corners k=1,2,3,4k = 1, 2, 3, 4Using C0=1C_0 = \pathcount{1}, C1=1C_1 = \pathcount{1}, C2=2C_2 = \pathcount{2}, C3=5C_3 = \pathcount{5}:
C4=C0C3+C1C2+C2C1+C3C0=(1)(5)+(1)(2)+(2)(1)+(5)(1)=5+2+2+5=14\displaystyle \begin{aligned} C_4 &= \firstleg{C_0} \secondleg{C_3} + \firstleg{C_1} \secondleg{C_2} \\ &\quad + \firstleg{C_2} \secondleg{C_1} + \firstleg{C_3} \secondleg{C_0} \\ &= (\firstleg{1})(\secondleg{5}) + (\firstleg{1})(\secondleg{2}) \\ &\quad + (\firstleg{2})(\secondleg{1}) + (\firstleg{5})(\secondleg{1}) \\ &= 5 + 2 + 2 + 5 = \pathcount{14} \end{aligned}

For any n≥1n \ge 1, pairing the earlier Catalan numbers from the ends inward gives the Catalan recurrence:

Cn\displaystyle C_n =C0Cn−1+C1Cn−2+C2Cn−3+⋯+Cn−1C0\displaystyle = \firstleg{C_0} \secondleg{C_{n-1}} + \firstleg{C_1} \secondleg{C_{n-2}} + \firstleg{C_2} \secondleg{C_{n-3}} + \dots + \firstleg{C_{n-1}} \secondleg{C_0}
8

Triangulating Polygons

Now we want to find how many ways a convex polygon can be sliced into triangles by diagonals that never cross each other. A hexagon always cuts into 44 triangles (and an (n+2)(n+2)-sided polygon cuts into nn triangles), and we can count the triangulations by looking at the single triangle that uses the yellow bottom edge.

Triangulating Polygons
ways to triangulate=  ?\text{ways to triangulate} = \;?
Text solution
Pick the top vertex of the yellow bottom-edge triangleIn a hexagon (44 triangles), the third corner of the bottom-edge triangle must be one of the 44 top vertices, which splits the remaining 33 triangles into a Left polygon and a Right polygon.
Multiply the Left and Right counts and add across all 44 verticesMoving the tip from Vertex 11 on the far left to Vertex 44 on the far right splits the remaining 33 triangles into pairs of sizes (0,3)(\firstleg{0},\secondleg{3}), (1,2)(\firstleg{1},\secondleg{2}), (2,1)(\firstleg{2},\secondleg{1}), and (3,0)(\firstleg{3},\secondleg{0}).
Total triangulations=C0C3+C1C2+C2C1+C3C0=(1)(5)+(1)(2)+(2)(1)+(5)(1)=14\displaystyle \begin{aligned} &\text{Total triangulations} \\ &\quad = \firstleg{C_0} \secondleg{C_3} + \firstleg{C_1} \secondleg{C_2} \\ &\qquad + \firstleg{C_2} \secondleg{C_1} + \firstleg{C_3} \secondleg{C_0} \\ &\quad = (\firstleg{1})(\secondleg{5}) + (\firstleg{1})(\secondleg{2}) \\ &\qquad + (\firstleg{2})(\secondleg{1}) + (\firstleg{5})(\secondleg{1}) \\ &\quad = \pathcount{14} \end{aligned}

So a hexagon has C4=14C_4 = \pathcount{14} triangulations, and any convex (n+2)(n+2)-sided polygon (which cuts into nn triangles) has CnC_n triangulations.

As the top vertex of the yellow bottom-edge triangle moves from left to right around the polygon, the Left and Right polygons trade one triangle at a time, stepping through the products C0Cn−1\firstleg{C_0} \secondleg{C_{n-1}}, C1Cn−2\firstleg{C_1} \secondleg{C_{n-2}}, …\dots, Cn−1C0\firstleg{C_{n-1}} \secondleg{C_0}.

Every corner the bottom triangle's tip can land on splits the remaining 3 triangles of the hexagon between a Left polygon and a Right polygon.

Key concepts

When you are counting paths or structures built step by step, pick your method based on the obstacles in the grid:

Open grids vs. roadblocks

On an open grid from (0,0)(0,0) to (m,n)(m,n), every walk is an (m+n)(m+n)-letter word with mm R\text{R}'s and nn U\text{U}'s, giving C(m+n,n)C(m+n, n) paths (for (4,3)(4,3), C(7,3)=35C(7,3) = \pathcount{35}). If a path must pass through (a,b)(a,b), split the trip into two legs and multiply C(a+b,b)×C((m−a)+(n−b),n−b)\firstleg{C(a+b, b)} \times \secondleg{C((m-a)+(n-b), n-b)}. When C(m+n,n)C(m+n,n) alone isn't the answer: if the grid has closed intersections, don't plug straight into C(m+n,n)C(m+n,n). Instead, fill the bottom and left edges with 1\pathcount{1}'s, write 0\fails{0} on every blocked corner, and add the corner to the left plus the corner below, one corner at a time.

Diagonal boundaries and the reflection method

If an n×nn \times n walk from (0,0)(0,0) to (n,n)(n,n) can never let U\text{U}'s outnumber R\text{R}'s (like nn pairs of brackets or an empty register with nn $5\$5 bills and nn $10\$10 bills), the count is the nnth Catalan number

Cn\displaystyle C_n =C(2n,n)−C(2n,n−1)\displaystyle = C(2n,n) - \fails{C(2n,n-1)} =1n+1C(2n,n)\displaystyle = \pathcount{\frac{1}{n+1}}C(2n,n)

with C0C_0 == 1\pathcount{1}, C1C_1 == 1\pathcount{1}, C2C_2 == 2\pathcount{2}, C3C_3 == 5\pathcount{5}, C4C_4 == 14\pathcount{14}, C5C_5 == 42\pathcount{42}. When not to plug into CnC_n: if the grid is rectangular (m≠nm \ne n) or you start with ss starter supplies (moving the red forbidden line to y=x+c\redline{y = x + c} where c=s+1c = s + 1), reflect the destination (m,n)(m,n) across y=x+c\redline{y = x + c} by swapping to (n,m)\swapped{(n,m)} and shifting cc left and cc up to (n−c,m+c)\fails{(n-c, m+c)}, then subtract the bad paths C(m+n,n−c)\fails{C(m+n, n-c)} from C(m+n,n)C(m+n, n) (for (6,3)(6,3) across y=x+2\redline{y = x + 2}, reflect to (1,8)\fails{(1,8)} to get C(9,3)−C(9,1)=75C(9,3) - \fails{C(9,1)} = \pathcount{75}).

The Catalan recurrence

When a problem of size nn splits at one first choice (such as a path's first return (k,k)(k,k) to the diagonal, or the yellow bottom-edge triangle of an (n+2)(n+2)-sided polygon) into two independent pieces of sizes k−1\firstleg{k - 1} and n−k\secondleg{n - k}, the count builds as

Cn\displaystyle C_n =C0Cn−1+C1Cn−2+⋯+Cn−1C0\displaystyle = \firstleg{C_0} \secondleg{C_{n-1}} + \firstleg{C_1} \secondleg{C_{n-2}} + \dots + \firstleg{C_{n-1}} \secondleg{C_0}
9

Practice

1

On a street grid, you walk from (0,0)(0,0) to (8,5)(8,5) taking only steps Right (R\text{R}) and Up (U\text{U}). How many shortest paths are there in total, and how many of them pass through the corner (5,2)(5,2)?

Treat the walk through (5,2)(5,2) as two back-to-back trips: first from (0,0)(0,0) to (5,2)(5,2), and then from (5,2)(5,2) to (8,5)(8,5). How many steps Right and Up are left for the second leg?

Every path from (0,0)(0,0) to (8,5)(8,5) takes 8+5=138 + 5 = 13 steps and chooses 55 to go Up, giving C(13,5)=1,287C(13,5) = \pathcount{1{,}287} total paths. A path through (5,2)(5,2) walks from (0,0)(0,0) to (5,2)(5,2) in C(5+2,2)=C(7,2)=21C(5+2, 2) = C(7,2) = \firstleg{21} ways, and then has 8−5=38 - 5 = \secondleg{3} steps Right and 5−2=35 - 2 = \secondleg{3} steps Up left to reach (8,5)(8,5) in C(3+3,3)=C(6,3)=20C(3+3, 3) = C(6,3) = \secondleg{20} ways. (Watch out: don't add the two legs to get 21+20=41\firstleg{21} + \secondleg{20} = 41, and don't forget to subtract (5,2)(5,2) from (8,5)(8,5) before counting the second leg.) Multiplying the two legs gives 21×20=420\firstleg{21} \times \secondleg{20} = \pathcount{420}.
2

On a 4×44 \times 4 grid from (0,0)(0,0) to (4,4)(4,4), intersections (1,2)(1,2) and (3,1)(3,1) are closed for construction. Find the number of shortest paths from (0,0)(0,0) to (4,4)(4,4) that avoid both closed intersections.

Put 11's along the bottom and left edges, place a 00 at both (1,2)(1,2) and (3,1)(3,1), and fill in the grid row by row by adding the corner to the left and the corner below.

Setting (1,2)\fails{(1,2)} and (3,1)\fails{(3,1)} to 0\fails{0} and adding the corner to the left plus the corner below row by row from y=0y = 0 to y=4y = 4 gives:
Row y=0y = 0: 1,1,1,1,11, 1, 1, 1, 1
Row y=1y = 1: 1,2,3,0,11, 2, 3, \fails{0}, 1
Row y=2y = 2: 1,0,3,3,41, \fails{0}, 3, 3, 4 (Watch out: at (3,2)(3,2), add 33 from the left and 0\fails{0} from (3,1)\fails{(3,1)} below; carrying up the unblocked count 44 from (3,1)\fails{(3,1)} gives 3636 at the end instead of 24\pathcount{24}.)
Row y=3y = 3: 1,1,4,7,111, 1, 4, 7, 11
Row y=4y = 4: 1,2,6,13,241, 2, 6, 13, \pathcount{24}
3

How many arrangements of 66 opening parentheses `(` and 66 closing parentheses `)` are properly nested?

Reading from left to right, a string of 66 `(` (R\text{R}) and 66 `)` (U\text{U}) is properly nested when it never crosses above y=xy = x. Which Catalan number counts a 6×66 \times 6 grid walk?

Properly nested arrangements of 66 pairs match paths from (0,0)(0,0) to (6,6)(6,6) that stay on or below y=xy = x, which is the 66th Catalan number C6C_6. (Watch out: C(12,6)=924C(12,6) = 924 counts all arrangements without the nesting rule, and if you use 1n+1C(2n,n)\pathcount{\frac{1}{n+1}}C(2n,n), divide by 6+1=76 + 1 = 7, not by 66 which gives 154154.) Subtracting the reflected bad paths gives C6C_6 == C(12,6)−C(12,5)C(12,6) - \fails{C(12,5)} == 924−792924 - \fails{792} == 132\pathcount{132}.
4

Tickets cost $5\$5 and the cash register starts empty. If 77 customers have a $5\$5 bill and 44 customers have a $10\$10 bill, in how many orders can the 1111 customers line up so the cashier never runs out of change? (Count two lines as the same order when they have the same sequence of $5\$5 and $10\$10 bills.)

This is a rectangular walk from (0,0)(0,0) to (7,4)(7,4) that cannot touch the forbidden line y=x+1y = x + 1. Where does (7,4)(7,4) land when you swap its coordinates and shift 11 step left and 11 step up?

There are C(7+4,4)=C(11,4)=330C(7+4, 4) = C(11,4) = 330 total paths from (0,0)(0,0) to (7,4)(7,4). Reflecting (7,4)(7,4) across y=x+1\redline{y = x + 1} swaps the coordinates to (4,7)\swapped{(4,7)} and shifts 11 step left and 11 step up to (3,8)\fails{(3,8)}. (Watch out: don't divide 330330 by n+1n + 1 as if the grid were square, and don't stop at (4,7)\swapped{(4,7)} without shifting by 11, which would subtract C(11,4)=330C(11,4) = 330 and give 00.) Subtracting the C(11,3)=165\fails{C(11,3) = 165} bad paths to (3,8)\fails{(3,8)} gives 330−165=165330 - \fails{165} = \pathcount{165}.
5

Suppose 55 customers have a $5\$5 bill and 55 customers have a $10\$10 bill, but the cashier starts with two $5\$5 bills already in the register. In how many orders can the 1010 customers line up so the cashier never runs out of change? (Count two lines as the same order when they have the same sequence of $5\$5 and $10\$10 bills.)

With two $5\$5 bills already in the drawer, how many more $10\$10 bills (U\text{U}) than $5\$5 bills (R\text{R}) does it take to empty the register and hit the forbidden line y=x+cy = x + c?

With 22 starter $5\$5 bills, the cashier only runs out of change when a path reaches 2+1=32 + 1 = 3 more U\text{U}'s than R\text{R}'s, putting the forbidden line at y=x+3\redline{y = x + 3}. (Watch out: using y=x+2y = x + 2 shifts (5,5)(5,5) to (3,7)(3,7) and subtracts C(10,3)=120C(10,3) = 120 bad paths, giving 132132 instead of 207\pathcount{207}.) Reflecting (5,5)(5,5) across y=x+3\redline{y = x + 3} shifts 33 steps left and 33 steps up to (2,8)\fails{(2,8)}, giving C(10,2)=45\fails{C(10,2) = 45} bad paths out of C(10,5)=252C(10,5) = 252 total paths, and 252−45=207252 - \fails{45} = \pathcount{207}.
6

How many paths from (0,0)(0,0) to (6,6)(6,6) stay below the diagonal y=xy = x at every step and touch the diagonal only at the start (0,0)(0,0) and the end (6,6)(6,6)? How many paths from (0,0)(0,0) to (6,6)(6,6) stay on or below the diagonal and touch it for the first time after (0,0)(0,0) at (2,2)(2,2)?

A path whose first return to the diagonal is at (k,k)(k,k) takes 11 forced step Right from (0,0)(0,0) and 11 forced step Up into (k,k)(k,k), shrinking the walk between them to size k−1k - 1. What is kk in each question?

A path that touches the diagonal only at (0,0)(0,0) and (6,6)(6,6) has its first return at k=6k = 6, so its first step R\text{R} to (1,0)(1,0) and last step U\text{U} from (6,5)(6,5) are forced, shrinking the walk between them to a 5×5\firstleg{5 \times 5} Catalan walk in C5=42\firstleg{C_5} = \pathcount{42} ways (not C6=132C_6 = 132). A path whose first return is at (2,2)(2,2) has C2−1=C1=1\firstleg{C_{2-1} = C_1 = 1} way from (0,0)(0,0) to (2,2)(2,2) (not C2=2C_2 = 2, which would give 2×14=282 \times 14 = 28) and C6−2=C4=14\secondleg{C_{6-2} = C_4 = 14} ways from (2,2)(2,2) to (6,6)(6,6), giving C1C4=1×14=14\firstleg{C_1} \secondleg{C_4} = \firstleg{1} \times \secondleg{14} = \pathcount{14}.
7

In how many ways can a convex octagon (88-sided polygon) be sliced into 66 triangles by non-crossing diagonals? How many of those triangulations have the bottom edge belonging to a triangle whose tip splits the rest of the octagon into a quadrilateral on the left and a pentagon on the right?

Count how many triangles each polygon cuts into (22 fewer than its number of sides) to pick the right Catalan subscripts for the total and for the Left-and-Right split.

An 88-sided octagon cuts into 8−2=68 - 2 = 6 triangles in C6C_6 == C0C5+C1C4+C2C3+C3C2+C4C1+C5C0\firstleg{C_0} \secondleg{C_5} + \firstleg{C_1} \secondleg{C_4} + \firstleg{C_2} \secondleg{C_3} + \firstleg{C_3} \secondleg{C_2} + \firstleg{C_4} \secondleg{C_1} + \firstleg{C_5} \secondleg{C_0} =42+14+10+10+14+42=132= 42 + 14 + 10 + 10 + 14 + 42 = \pathcount{132} ways. (Watch out: index by the number of triangles, not the number of sides; using sides gives C8=1,430C_8 = 1{,}430 and C4C5=588C_4 C_5 = 588.) A quadrilateral on the left (22 triangles, C2=2\firstleg{C_2 = 2} ways) and a pentagon on the right (33 triangles, C3=5\secondleg{C_3 = 5} ways) can be triangulated in C2C3=2×5=10\firstleg{C_2} \secondleg{C_3} = \firstleg{2} \times \secondleg{5} = \pathcount{10}.
8

Fix integers m≥n≥0m \ge n \ge 0. By counting shortest paths from (0,0)(0,0) to (m,n)(m,n) in two ways, first all at once and then split after the first mm steps, prove that C(m,0)C(n,0)+C(m,1)C(n,1)+⋯+C(m,n)C(n,n)C(m,0)C(n,0) + C(m,1)C(n,1) + \dots + C(m,n)C(n,n) == C(m+n,n)C(m+n,n).

If a path takes kk steps Up during its first mm steps, it takes m−km - k steps Right in that first leg. How many steps Right does it still need during its final nn steps?

Counting all at once, every path from (0,0)(0,0) to (m,n)(m,n) takes m+nm + n steps with nn steps Up, giving C(m+n,n)C(m+n,n) paths. Counting by splitting after the first mm steps, a path that takes k\firstleg{k} steps Up in its first mm steps (where 0≤k≤n0 \le k \le n) takes m−k\firstleg{m - k} steps Right, so it has m−(m−k)=km - (m - k) = \secondleg{k} steps Right left to take during its final nn steps. (Choosing which kk of the final nn steps go Right gives C(n,k)\secondleg{C(n,k)} directly; choosing which n−kn - k go Up gives C(n,n−k)\secondleg{C(n, n-k)}, which is the same number.) There are C(m,k)\firstleg{C(m,k)} ways to choose the kk Up-steps in the first mm steps and C(n,k)\secondleg{C(n,k)} ways to choose the kk Right-steps in the last nn steps, giving C(m,k)C(n,k)\firstleg{C(m,k)}\secondleg{C(n,k)} paths for each kk. Summing over k=0,1,…,nk = 0, 1, \dots, n counts every path to (m,n)(m,n) once and gives C(m,0)C(n,0)+C(m,1)C(n,1)+⋯+C(m,n)C(n,n)\firstleg{C(m,0)}\secondleg{C(n,0)} + \firstleg{C(m,1)}\secondleg{C(n,1)} + \dots + \firstleg{C(m,n)}\secondleg{C(n,n)} == C(m+n,n)C(m+n,n).