# Added 2 different implementations for Catalan Numbers #255

Merged
merged 9 commits into from Dec 31, 2017

Contributor

## SHORT DESCRIPTION

Added 2 different implementations of catalan numbers which vary in time complexity only!

## TESTING

Just run the program and you'll get the outcome! The results of both the programs will be the same! They're just different methods to find catalan numbers

### rahulkumaran added some commits Dec 25, 2017

``` Added 2 different implementations for Catalan Numbers ```
``` 24f5deb ```
``` Update catalan_binomial.py ```
``` c29e3a9 ```
Contributor Author

### rahulkumaran commented Dec 25, 2017

 @prateekiiest sorry closed the previous PR! Had some implementation faults in that! So just rectified my code and made the necessary changes! :) Please have a look at it :)
referenced this pull request Dec 25, 2017
``` Create README.md ```
``` ef9b750 ```

### prateekiiest reviewed Dec 28, 2017

 The 2 different implementations vary only in terms of time taken!
Basically we can implement in 3 different ways!
(1) Recursively

#### prateekiiest Dec 28, 2017

Member

instead of numbering use `*`.

And write the time complexities here only like this

• Recursive -exponential

Member

### prateekiiest left a comment

 see the reviews
``` Update README.md ```
``` ad8540e ```
Contributor Author

### rahulkumaran commented Dec 28, 2017

 @prateekiiest made the changes you requested :)

Member

### prateekiiest left a comment

 Just a few niggly comments. Otherwise its good to go 🎆
 (2) Dynamic Programming
(3) Binomial Coefficient

* Recursively - Exponential time complexity
* Dynamic Programming - O(n^2)

#### prateekiiest Dec 28, 2017

Member

make a tilde before and after O(n^2)

 @@ -0,0 +1,17 @@ The 2 different programs in this folder contain the same implementation!

Member

#### rahulkumaran Dec 29, 2017

Author Contributor

done

 The Binomial implementation has the best time complexity while the Recursive implementation has the worst time complexity
In this folder we have the Binomial and Recursive implementations of Catalan Numbers.

Sources : https://www.geeksforgeeks.org/program-nth-catalan-number/ (You can have a look at this to know more about Catalan number implementations and its theory.)

Member

#### rahulkumaran Dec 29, 2017

Author Contributor

done

 The Binomial implementation has the best time complexity while the Recursive implementation has the worst time complexity
In this folder we have the Binomial and Recursive implementations of Catalan Numbers.

Sources : https://www.geeksforgeeks.org/program-nth-catalan-number/ (You can have a look at this to know more about Catalan number implementations and its theory.)

#### prateekiiest Dec 28, 2017

Member

some examples needed where catalan number comes in like finding no. of polygon triangulation etc.

 return 1 res = 0 #Result has been initialised to 0 for i in range(n): res += catalan_numbers(i) * catalan_numbers(n-i-1) #The recursive function call

#### prateekiiest Dec 28, 2017

Member

where is the coefficient in this case?

#### rahulkumaran Dec 29, 2017

Author Contributor

@prateekiiest what coefficient are you referring to?

#### prateekiiest Dec 30, 2017

Member

The combination C factor

 c = binCoeff(2*n, n) #Finding value of c by calling the binCoeff function return c/(n + 1) #This is the final catalan number for i in range (5): #finds 1st 5 catalan numbers

#### prateekiiest Dec 28, 2017

Member

just print one or two catalan numbers as example, not in a for loop

#### rahulkumaran Dec 29, 2017

Author Contributor

done

 The 2 different implementations vary only in terms of time taken!
Basically we can implement in 3 different ways!
* Recursively - Exponential time complexity

#### prateekiiest Dec 28, 2017

Member

make use of tilde

like this `O(n^2)`

#### rahulkumaran Dec 29, 2017

Author Contributor

done

### rahulkumaran added some commits Dec 29, 2017

``` Update README.md ```
``` 70fb09c ```
``` Update README.md ```
``` 9a1fc8c ```
``` Update catalan_binomial.py ```
``` e63ac07 ```
``` Update catalan_recursive.py ```
``` e3cac9d ```
``` Update README.md ```
``` 099e891 ```

### prateekiiest merged commit `cfba6e1` into codeIIEST:master Dec 31, 2017 4 checks passed

#### 4 checks passed

Codacy/PR Quality Review Good work! A positive pull request.
Details
codebeat no reportable quality changes
Details
codeclimate All good!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details