banner
xihale

xihale

github
pixiv
pixiv
tg_channel

A Brief Discussion on Catalan Numbers

Introduction#

The essence of CatalanCatalan is recursion, and many problems have a recursive form similar to that of CatalanCatalan, indicating that they share commonalities and can utilize the thinking methods of CatalanCatalan numbers, which opens a new window for us in problem-solving.

Definition#

  • A:sequencelength|A|: sequence length
  • asetofsolutions:astringofvalidsequencesa set of solutions: a string of valid sequences
  • operator +:sequenceconcatenationoperator\ +: sequence concatenation

Number of Binary Tree Types Problem#

Divide and conquer: left + self + right

We have the following definition

Hn={1,n=0,1i=1nHniHi1,n2H_n=\begin{cases} 1, n=0,1\\ \sum_{i=1}^nH_{n-i}\cdot H_{i-1}, n\geq 2 \end{cases}

Valid Sequences#

nn instances of +1+1 and nn instances of 1-1 form 2n2n terms a1,a2,,a2na_1,a_2, \cdots ,a_{2n}, whose partial sums satisfy a1+a2++ak0(k=1,2,3,,2n)a_1+a_2+ \cdots +a_k \geq 0(k=1,2,3, \cdots ,2n) What is this sequence for nn?

At first glance, it seems difficult, but let's analyze it carefully.

It seems inconvenient to obtain the result directly, so we use the principle of inclusion-exclusion.

We subtract the number of invalid sequences from the total.

Total Count#

Place nn instances of +1+1 in a long 2n2n sequence, with the rest being 1-1, thus the total count is (2nn)\binom{2n}{n}.

Invalid Count#

First, we consider the invalid cases.
There is only one situation that leads to invalidity:
That is, during the process of some prefix sum, the partial sum first becomes less than zero.

Constructing Invalid Count#

Let AA be a set of valid solutions, and BB be any sequence (simultaneously satisfying that BB is missing exactly one 1-1 and has B=n1|B|=n-1).
That is, A+B=2n1|A|+|B|=2n-1.

Clearly, at this point, we have H=(A,1,B)H=(A, -1, B), which is a set of invalid solutions.

Warning

At this point, although it is an invalid solution, the counts of +1+1 and 1-1 in HH are both nn.

How do we distinguish between valid and invalid solutions?
We define (taking the complement of the BB sequence)

Bi^={+1,Bi=11,Bi=+1\hat{B_i}=\begin{cases} +1, B_i=-1\\ -1, B_i=+1 \end{cases}

Now B^\hat{B} is a sequence that has one more and only one more 1-1 (it has changed from having one less to one more).

Now H^=(A,1,B^)\hat{H}=(A, -1, \hat{B}) is a sequence with n+1n+1 instances of 1-1 and n1n-1 instances of +1+1.

It seems we have distinguished them; let's verify the feasibility.
Consider whether it can be done without omission or duplication.

Carefully thinking, B^\hat{B} and BB form a bijective set.
This means that all invalid solutions correspond to such a H^\hat{H}.

So how do we count them?
We can enumerate the counts of +1+1 or 1-1.

That is (2nn1)\binom{2n}{n-1} or (2nn+1)\binom{2n}{n+1}.

Final Solution#

Hn=(2nn)(2nn1)H_n=\binom{2n}{n}-\binom{2n}{n-1}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.