- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to calculate catalan numbers with the method of Binominal Coefficients using Python?
To calculate Catalan numbers using binomial Coefficients, you first need to write a function that calculates binomial coefficients.
example
def binomialCoefficient(n, k): # To optimize calculation of C(n, k) if (k > n - k): k = n - k coeff = 1 for i in range(k): coeff *= (n - i) coeff /= (i + 1) return coeff def catalan(n): return binomialCoefficient(2*n, n) / (n + 1) for i in range (11): print (catalan(i))
Output
This will give the output −
1.0 1.0 2.0 5.0 14.0 42.0 132.0 429.0 1430.0 4862.0 16796.0
Advertisements