Skip to content

Conversation

Supriyasus
Copy link

Describe your change:

Added an enhanced implementation of the 0-N Knapsack Problem that includes both:

  • A recursive version (optimized using functools.cache)
  • A dynamic programming (DP) version for better performance on larger inputs

The code now adheres to PEP 8 and Ruff style rules, replacing @lru_cache(maxsize=None) with @cache (UP033) and ensuring all lines are ≤ 88 characters (E501).
Additionally, the function API has been simplified — the redundant counter parameter was removed, and a new method argument was added to choose between 'recursive' and 'dp' implementations.

Doctests and documentation have been updated to reflect these improvements.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Supriyasus and others added 4 commits October 8, 2025 17:53
add DP implementation and improve recursive version
replace lru_cache with cache and fix line length
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant