Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 2 different implementations for Catalan Numbers #255

Merged
merged 9 commits into from Dec 31, 2017

Conversation

@rahulkumaran
Copy link
Contributor

commented Dec 25, 2017

Thank you for your contribution. Please provide the details requested below.

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

@rahulkumaran

This comment has been minimized.

Copy link
Contributor Author

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 :)

The 2 different implementations vary only in terms of time taken!<br>
Basically we can implement in 3 different ways!<br>

(1) Recursively <br>

This comment has been minimized.

Copy link
@prateekiiest

prateekiiest Dec 28, 2017

Member

instead of numbering use *.

And write the time complexities here only like this

  • Recursive -exponential
@prateekiiest
Copy link
Member

left a comment

see the reviews

@rahulkumaran

This comment has been minimized.

Copy link
Contributor Author

commented Dec 28, 2017

@prateekiiest made the changes you requested :)

@prateekiiest
Copy link
Member

left a comment

Just a few niggly comments.

Otherwise its good to go 🎆

(2) Dynamic Programming <br>
(3) Binomial Coefficient <br><br>
* Recursively - Exponential time complexity<br>
* Dynamic Programming - O(n^2)<br>

This comment has been minimized.

Copy link
@prateekiiest

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!

This comment has been minimized.

Copy link
@prateekiiest

prateekiiest Dec 28, 2017

Member

two instead of 2

This comment has been minimized.

Copy link
@rahulkumaran

rahulkumaran Dec 29, 2017

Author Contributor

done

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

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.)

This comment has been minimized.

Copy link
@prateekiiest

prateekiiest Dec 28, 2017

Member

embed this link

This comment has been minimized.

Copy link
@rahulkumaran

rahulkumaran Dec 29, 2017

Author Contributor

done

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

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.)

This comment has been minimized.

Copy link
@prateekiiest

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

This comment has been minimized.

Copy link
@prateekiiest

prateekiiest Dec 28, 2017

Member

where is the coefficient in this case?

This comment has been minimized.

Copy link
@rahulkumaran

rahulkumaran Dec 29, 2017

Author Contributor

@prateekiiest what coefficient are you referring to?

This comment has been minimized.

Copy link
@prateekiiest

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

This comment has been minimized.

Copy link
@prateekiiest

prateekiiest Dec 28, 2017

Member

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

This comment has been minimized.

Copy link
@rahulkumaran

rahulkumaran Dec 29, 2017

Author Contributor

done

The 2 different implementations vary only in terms of time taken!<br>
Basically we can implement in 3 different ways!<br>

* Recursively - Exponential time complexity<br>

This comment has been minimized.

Copy link
@prateekiiest

prateekiiest Dec 28, 2017

Member

make use of tilde

like this O(n^2)

This comment has been minimized.

Copy link
@rahulkumaran

rahulkumaran Dec 29, 2017

Author Contributor

done

rahulkumaran added some commits Dec 29, 2017

@prateekiiest prateekiiest merged commit cfba6e1 into codeIIEST:master Dec 31, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.