-
Notifications
You must be signed in to change notification settings - Fork 163
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
Conversation
@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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the reviews
@prateekiiest made the changes you requested :) |
There was a problem hiding this 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> |
There was a problem hiding this comment.
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two instead of 2
There was a problem hiding this comment.
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.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
embed this link
There was a problem hiding this comment.
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.) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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