Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

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 sum j can be achieved using the first i elements of the array. This is a classic dynamic programming problem with applications in resource allocation, partitioning, and combinatorial optimization.

  • Implements subset sum problem using DP approach
  • Includes comprehensive test cases with edge cases (empty arrays, zero sum, single elements)
  • Time complexity: O(n * sum) where n is array length and sum is the target value
  • Space complexity: O(n * sum) for the DP table

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran below commands using the latest version of rust nightly.

  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.

  • I ran cargo fmt just before my last commit.

  • I ran cargo test just before my last commit and all tests passed.

  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).

  • I added my algorithm to DIRECTORY.md with the correct link.

  • I checked CONTRIBUTING.md and my code follows its guidelines.

  • Code structure follows repository patterns

  • All tests are included and logically sound

  • Documentation is comprehensive with examples

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

codecov-commenter commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.44%. Comparing base (13710a7) to head (b61bec3).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AliAlimohammadi
Copy link
Contributor Author

Hi @siriak. Could you please take a look at this PR? Thanks.

@siriak siriak requested a review from Copilot November 28, 2025 07:53
Copilot finished reviewing on behalf of siriak November 28, 2025 07:55
Copy link

Copilot AI left a 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.

@siriak
Copy link
Member

siriak commented Nov 28, 2025

Please check the comments

AliAlimohammadi and others added 3 commits November 28, 2025 00:03
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>
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak merged commit 1ce9f3a into TheAlgorithms:master Nov 28, 2025
7 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-subset-sum-algorithm branch November 28, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants