The Catalan Series
The article discusses Catalan numbers, a sequence used in combinatorial problems. It covers their recurrence relation, closed form, and applications in path counting. It provides insights into problem-solving using Catalan numbers.
Catalan Numbers
Catalan numbers can be applied to the following problems:
- There are people queuing up to enter a theater. The entrance fee is 5 yuan. Among them, only people have a 5 yuan bill, while the other people only have a 10 yuan bill. The theater has no other bills. How many ways are there to ensure that whenever a person with a 10 yuan bill buys a ticket, the ticket office has a 5 yuan bill for change?
- There is a grid of size with the lower left corner at and the upper right corner at . Starting from the lower left corner, you can only move one unit to the right or up each time, without going above the diagonal line . How many possible paths are there to reach the upper right corner without crossing the line ?
- Choose points on a circle and connect these points pairwise to obtain line segments. How many ways are there to ensure that the line segments obtained do not intersect?
- Without intersecting diagonals, how many ways are there to divide a convex polygon area into triangular regions?
- If the stack (infinite) has a push sequence of , how many different pop sequences are there?
- How many different binary trees can be constructed with nodes?
- Given numbers consisting of s and s, denoted as , such that the partial sum satisfies , how many sequences satisfy this condition?
The corresponding sequence is:
Recurrence Relation
The solution to this recurrence relation is:
Common formulas for Catalan numbers are:
A common application: for a stack, the push sequence is , find the total number of possible pop sequences.
#include <iostream>
using namespace std;
int n;
long long f[25];
int main() {
f[0] = 1;
cin >> n;
for (int i = 1; i <= n; i++) f[i] = f[i - 1] * (4 * i - 2) / (i + 1);
// Here, formula 2 is used
cout << f[n] << endl;
return 0;
}
Closed Form
The recurrence relation of Catalan numbers is
where and . Let its ordinary generating function be .
We find that the recurrence relation of Catalan numbers is similar to the form of convolution. Therefore, we construct an equation about using convolution:
Solving this equation, we get
Now, we have a question: which root should we take? Rationalizing the numerator, we get
Substituting , we obtain the constant term of , which is . When , we have , satisfying the requirement. The other root leads to the denominator being (non-convergence), so it is discarded.
Therefore, we obtain the closed form of the generating function of Catalan numbers:
Next, we need to expand it. But note that its denominator is not in the form of a polynomial like the Fibonacci sequence, so it is not convenient to use the expansion form of geometric sequences. Here we need to use Newton's binomial theorem. Let's first expand :
Note that
Here, we use the simplification technique of double factorials. Then, substitute into , we get
Substitute back into the original expression, we get
Thus, we obtain the general formula for Catalan numbers.
Path Counting Problem
Non-decreasing paths refer to paths that can only move upwards or to the right.
-
The number of non-decreasing paths from to is equal to the number of permutations of and , i.e., .
-
The number of non-decreasing paths from to that do not touch the line except at endpoints:
First, consider the paths below the line , which all start from , pass through and , and reach . This can be seen as the number of non-decreasing paths from to without touching .
All non-decreasing paths total . For any path that touches , we can symmetrically transform the part from the point where it leaves this line to , obtaining a non-decreasing path from to . The reverse is also true. Hence, the number of non-decreasing paths below is . Due to symmetry, the answer is .
-
The number of non-decreasing paths from to that do not cross the line : Similarly, we can obtain using similar methods.
NOTE: This article is rewritten by OI WIKI.