Skip to content

[FEATURE REQUEST] Optimized approach to Subset Sum problem #5600

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

Closed
Rupa-Rd opened this issue Oct 6, 2024 · 4 comments · Fixed by #5651
Closed

[FEATURE REQUEST] Optimized approach to Subset Sum problem #5600

Rupa-Rd opened this issue Oct 6, 2024 · 4 comments · Fixed by #5651

Comments

@Rupa-Rd
Copy link
Contributor

Rupa-Rd commented Oct 6, 2024

What would you like to Propose?

I would like to propose an space optimized solution to the Subset Sum problem.

Issue details

The existing subset sum problem solution's space complexity is O(n*sum).
By optimizing the algorithm/ approach further, we can achieve the space complexity of O(sum) which is more efficient than the existing one.

Algorithm link:
https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java

Additional Information

No response

@ssugam10
Copy link

ssugam10 commented Oct 6, 2024

kindly assign this issue to me

@Pranjul2002
Copy link

please assign this task to me. It will surely help you.
I will do my best.

@aayu5hgit
Copy link

Hey @Rupa-Rd

I'd like to propose a solution for this:

We can reduce the space complexity by using a 1D array instead of a 2D array. Since, at any point in the iteration, the result only depends on the current row and the previous row in the matrix. Therefore, we can maintain a single row and update it in reverse order (to avoid overwriting values).

Let me know if this works, I'm implementing this on my local machine until then :)

@lfcbird
Copy link

lfcbird commented Oct 7, 2024

Please assign to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants