-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add subset sum algorithm #956
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
Add subset sum algorithm #956
Conversation
- Implements subset sum problem using DP approach - Includes comprehensive test cases with edge cases - Time complexity: O(n * sum) - Space complexity: O(n * sum)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #956 +/- ##
==========================================
+ Coverage 95.39% 95.44% +0.05%
==========================================
Files 332 333 +1
Lines 21496 21524 +28
==========================================
+ Hits 20506 20544 +38
+ Misses 990 980 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @siriak. Could you please take a look at this PR? Thanks. |
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 implements the classic subset sum problem using dynamic programming. The algorithm determines whether a subset of a given array can sum to a target value using a 2D DP table approach where dp[i][j] represents if sum j is achievable using the first i elements.
Key changes:
- Adds subset sum DP algorithm with O(n * sum) time/space complexity
- Includes comprehensive test suite using macro-based test generation pattern
- Properly integrates into module system and documentation index
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/dynamic_programming/subset_sum.rs | New implementation of subset sum algorithm with DP approach, includes function implementation and test suite |
| src/dynamic_programming/mod.rs | Adds module declaration and public export for is_sum_subset function |
| DIRECTORY.md | Adds entry for Subset Sum in the dynamic programming algorithms directory listing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
|
Please check the comments |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 implements the Subset Sum Problem using dynamic programming. The algorithm determines whether there exists a subset of a given array that sums to a specified target value.
The implementation uses a 2D DP table where
dp[i][j]represents whether sumjcan be achieved using the firstielements of the array. This is a classic dynamic programming problem with applications in resource allocation, partitioning, and combinatorial optimization.Type of change
Checklist:
I ran below commands using the latest version of rust nightly.
I ran
cargo clippy --all -- -D warningsjust before my last commit and fixed any issue that was found.I ran
cargo fmtjust before my last commit.I ran
cargo testjust before my last commit and all tests passed.I added my algorithm to the corresponding
mod.rsfile within its own folder, and in any parent folder(s).I added my algorithm to
DIRECTORY.mdwith the correct link.I checked
CONTRIBUTING.mdand my code follows its guidelines.Code structure follows repository patterns
All tests are included and logically sound
Documentation is comprehensive with examples