Skip to content

Conversation

@Kunal-notfound
Copy link

@Kunal-notfound Kunal-notfound commented Jan 6, 2026

Description of Change

Closes #3091

This Pull Request improves the Unbounded Knapsack implementation by:

  1. Replacing the recursive solution with an iterative dynamic programming solution for better efficiency.
  2. Adding input validation to throw an error if the price and weight arrays have different lengths.
  3. Fixing Test Case-4 to match the correct expected behavior.
  4. Adding a new test case to verify that the input validation correctly throws an error.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:
This is my first PR so please ignore the cache files

@Kunal-notfound Kunal-notfound changed the title fix: Replacing the Recursive Unbound Knapsack Solution with iterative one Closes #3091 fix: Replacing the Recursive Unbound Knapsack Solution with iterative one Jan 6, 2026
@Kunal-notfound Kunal-notfound changed the title Closes #3091 fix: Replacing the Recursive Unbound Knapsack Solution with iterative one fix: Replacing the Recursive Unbound Knapsack Solution with iterative one Jan 6, 2026
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.

[FEATURE] Iterative Solution for Unbounded 0/1 Knapsack

1 participant