Derivation of the catlan math formula in taocp

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.