DP program: Catalan numbers #167
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Program for Catalan numbers
Description
A classic DP problem that is often asked in coding contests and interviews is solving for the nth Catalan number. Catalan numbers have numerous applications, like possible number of expressions with correctly matched parentheses, possible number of BSTs with
n
keys, and so many more. [Applications of Catalan Numbers - GeeksforGeeks]In my program
Using the technique of tabulation in dynamic programming, I have written a program that computes and prints the first
n+1
Catalan numbers, wheren
is given by the user.Although Catalan numbers have a factorial-based definition, the definition I used was a recursive one. This definition is written in the program as comments (shown below), and also available in its Uncyclopedia Page.
Why should this program be included in this repository
bits/stdc++.h
is not used; instead I have used the classiciostream
.struct
orclass
, so didn't use.main
function).Ending notes
If there is any mistake in my program, please notify in this PR conversation, and I shall try to improve them.
Looking forward to seeing this program in the repository!