-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add Catalan numbers implementation using dynamic programming #961
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
feat: add Catalan numbers implementation using dynamic programming #961
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #961 +/- ##
==========================================
+ Coverage 95.40% 95.48% +0.08%
==========================================
Files 334 336 +2
Lines 21576 21836 +260
==========================================
+ Hits 20585 20851 +266
+ Misses 991 985 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@siriak, This PR is ready to be merged. |
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.
Pull request overview
This PR adds a new dynamic programming implementation for computing Catalan numbers, a fundamental sequence in combinatorics used for counting problems such as valid parentheses combinations, binary trees, and Dyck words. The implementation uses the standard recurrence relation with O(n²) time complexity and O(n) space complexity.
Key Changes:
- Added
catalan_numbers.rswith a well-documented dynamic programming implementation - Updated module exports in
mod.rsto include the new function - Added entry to
DIRECTORY.mdfor documentation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/dynamic_programming/catalan_numbers.rs | New implementation of Catalan numbers using dynamic programming with comprehensive tests and documentation |
| src/dynamic_programming/mod.rs | Added module declaration and public export for catalan_numbers, maintaining alphabetical order |
| DIRECTORY.md | Added entry for Catalan Numbers algorithm (indentation issue noted) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
AliAlimohammadi
left a comment
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.
Review completed.
siriak
left a comment
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.
Looks good, thanks!
Description
This PR adds an implementation of Catalan Numbers using dynamic programming.
The Catalan numbers are a fundamental sequence in combinatorics that appear in numerous counting problems, including:
()()vs())()Algorithm Overview:
The implementation uses dynamic programming with the recurrence relation:
Time Complexity: O(n²)
Space Complexity: O(n)
The function computes all Catalan numbers from C(0) through C(upper_limit) and returns them as a vector.
References:
Type of change
Checklist:
cargo clippy --all -- -D warningsjust before my last commit and fixed any issue that was found.cargo fmtjust before my last commit.cargo testjust before my last commit and all tests passed.mod.rsfile within its own folder, and in any parent folder(s).DIRECTORY.mdwith the correct link.CONTRIBUTING.mdand my code follows its guidelines.Note: All tests run quickly (well under 300ms) as they only compute Catalan numbers up to C(10).