Topics
The Catalan numbers () count various recursive patterns, with balanced parentheses being a classic example. Let’s break this down step by step:
First, what are we counting?
- represents the number of ways to properly match n pairs of parentheses
- For example, when n=2, we have valid arrangements:
(())
and()()
Now, let’s understand the recursive formula using n=3 as an example. The key insight is:
- Every valid sequence must start with an opening parenthesis
(
- This opening parenthesis must have a matching closing parenthesis
)
- These matching parentheses divide our sequence into two parts: what’s inside them and what’s outside them
For n=3, let’s see how this works:
-
If we have 1 pair inside the first matching parentheses:
- Inside: We need to arrange 1 pair → ways
- Outside: We have 1 pair left → ways
- Example:
(())()
-
If we have 0 pairs inside:
- Inside: Empty → ways (just 1 way)
- Outside: 2 pairs → ways
- Example:
()()()
or()(())
-
If we have 2 pairs inside:
- Inside: 2 pairs → ways
- Outside: 0 pairs → ways
- Example:
((()))
The total number is the sum of all these possibilities:
This pattern generalizes to the formula (combinatorial proof here):
The formula captures the fact that we’re:
- Always using one pair of parentheses as our “outer frame”
- Splitting the remaining n-1 pairs between “inside” (i pairs) and “outside” (n-1-i pairs)
- Multiplying the possibilities for each part (because we can combine any valid inside arrangement with any valid outside arrangement)
- Summing over all possible ways to split the remaining pairs
This way to breaking problems is a common pattern that is seen in many places:
- balanced parentheses/bracket sequences
- counting full binary trees (unlabelled)
- for labelled: since we can assign labels to nodes in ways
- paths in a grid without crossing the diagonal
- triangulations of a convex polygon: A pentagon can be triangulated in ways
- number of mountain ranges (dyck paths)
- number of ways to connect disjoint chords