Consider a n x n grid with indexes of top left corner as (0, 0). Dyck path is a staircase walk from bottom left, i.e., (n-1, 0) to top right, i.e., (0, n-1) that lies above the diagonal cells (or cells on line from bottom left to top right).
The task is to count the number of Dyck Paths from (n-1, 0) to (0, n-1).
Input : n = 1 Output : 1 Input : n = 2 Output : 2 Input : n = 3 Output : 5 Input : n = 4 Output : 14
The number of Dyck paths from (n-1, 0) to (0, n-1) can be given by the Catalan numberC(n).
We strongly recommend that you click here and practice it, before moving on to the solution.
Below are the implementations to find count of Dyck Paths (or n’th Catalan number).
Number of Dyck Paths is 14
- Find number of sequences of 1 and -1 such that every sequence follows below constraints :
a) The length of a sequence is 2n
b) There are equal number of 1’s and -1’s, i.e., n 1’s, n -1s
c) Sum of prefix of every sequence is greater than or equal to 0. For example, 1, -1, 1, -1 and 1, 1, -1, -1 are valid, but -1, -1, 1, 1 is not valid.
- Number of paths of length m + n from (m-1, 0) to (0, n-1) that are restricted to east and north steps.
This article is contributed by Aditya Chatterjee. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Number of ways a convex polygon of n+2 sides can split into triangles by connecting vertices
- N-th term in the series 1, 11, 55, 239, 991,....
- k-th prime factor of a given number
- Find (a^b)%m where 'a' is very large
- Count 'd' digit positive integers with 0 as a digit
- Matrix Exponentiation
- Check if count of divisors is even or odd
- Applications of Catalan Numbers
- Print all Good numbers in given range
- Tiling Problem
- Program for nth Catalan Number
- Count all possible paths from top left to bottom right of a mXn matrix
- Space and time efficient Binomial Coefficient
- Binomial Coefficient | DP-9
- Program for Fibonacci numbers