Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added 2 different implementations for Catalan Numbers #255

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

Merged
prateekiiest merged 9 commits into codeIIEST:master from rahulkumaran:catalan
Dec 31, 2017

Conversation

Copy link
Contributor

@rahulkumaran rahulkumaran 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

Copy link
Contributor Author

@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>
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of numbering use *.

And write the time complexities here only like this

  • Recursive -exponential

Copy link
Member

@prateekiiest prateekiiest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the reviews

Copy link
Contributor Author

@prateekiiest made the changes you requested :)

Copy link
Member

@prateekiiest prateekiiest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two instead of 2

Copy link
Contributor Author

@rahulkumaran rahulkumaran Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

embed this link

Copy link
Contributor Author

@rahulkumaran rahulkumaran Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the coefficient in this case?

Copy link
Contributor Author

@rahulkumaran rahulkumaran Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prateekiiest what coefficient are you referring to?

Copy link
Member

@prateekiiest prateekiiest Dec 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@rahulkumaran rahulkumaran Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

@prateekiiest prateekiiest Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make use of tilde

like this O(n^2)

Copy link
Contributor Author

@rahulkumaran rahulkumaran Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@prateekiiest prateekiiest merged commit cfba6e1 into codeIIEST:master Dec 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@prateekiiest prateekiiest prateekiiest approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /