CATALAN NUMBERS:

unsigned long long ar[ ]= {1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452,18367353072152,69533550916004, 263747951750360, 1002242216651368, 3814986502092304, 14544636039226909 };
 
Formula:
Cn = 2nCn/(n+1) = 2n!/{(n+1)!n!}
we can also use this formula
C0 = 1
Cn = Cn-1*(4n-2)/(n+1)

 Source code:

Applications:

1. How many ways are there to construct n pairs of parentheses which are correctly matched.
[Analysis: The leftmost parenthesis l matches some right parenthesis r. Suppose there are k pairs between l and r, there will be n-k-1 pairs outside. Hence, the number of possibilities will be]

2. Counting the number of paths across a lattice which do not cross the diagonal line. More generally, Cn is the number of Dyck words of length 2n. A Dyck word is a string consisting of n X’s and n Y’s such that no initial segment of the string has more Y’s than X’s. eg: XXXYYY, XYXYXY, XYXXYY…

3. Counting the number of rooted ordered binary trees with n+1 leaves.

4. Counting the number of ways n+1 factors can be completely parenthesized.

5. Counting the number of ways of associating n applications of a binary operator.

6. Counting the number of ways a convex polygon with n+2 sides can be cut into trangiles by connecting vertices with straight lines.

7. Counting the number of ways to tile a stairstep shape of height n with n rectangles.

Resources:



Comments

Popular posts from this blog

HackerEarth: City and Campers 2 (DSU-UnionFind)

Two Pointers Technique & Binary Search For Beginners

Problem : Codeforces Round #406 (Div. 1) B [ Legacy ]( Dijakstra, Segment tree)