The general formula of the catlan number is:
As for how to deduce, the brilliant solution "reflection principle" mentioned in Exercise 4 of section 2.2.1 of "computer programming art (Volume 1)" is summarized as follows:
The problem is that the number of valid sequences (the number of S is N) is represented by S and X represents the number of outgoing stacks ).
Obviously, there are C (2n, n) sequences containing S and X, and the rest is to calculate the number of disallowed sequences (it contains the correct number of S and X, but violates other conditions ).
In any sequence that is not allowed, determine the first X position where the number of X exceeds the number of S. Then, in the sequence that leads to and includes this X, replace all X with S and represent all s with X. The result is a sequence with (n + 1) s and (n-1) X. In turn, we can reverse this process for each type of a scale, and find the sequence that causes the previous type of disallow. For example, xxsxsssxxsss must come from ssxsxxxxxsss. This correspondence shows that the number of disallowed sequences is C (2n, n-1), so an = C (2n, n)-C (2n, n-1 ).
For details, refer to the original exercise questions of taocp:
Here, I have reviewed and confirmed the proof method of the catlan pass cited by knuth. If you are interested, you can study it on your own.
Derivation of the catlan math formula in taocp