Add subset sum algorithm #956
Open
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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