Skip to content

Conversation

Arpita01-work
Copy link

@Arpita01-work Arpita01-work commented Oct 14, 2025

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted as per the project style.

💡 Description

This PR adds the 0/1 Knapsack Algorithm implemented in Java using a bottom-up Dynamic Programming approach.

Problem Statement:
Given n items with certain weights and values, and a knapsack with weight capacity W, determine the maximum total value without exceeding the capacity. Each item can either be included or excluded (0/1 condition).

File Path: src/main/java/com/thealgorithms/dynamicprogramming/Knapsack.java

Example:

int[] values = {60, 100, 120};
int[] weights = {10, 20, 30};
int W = 50;
System.out.println(Knapsack.knapSack(W, weights, values)); // Output: 220

Enhancement Type: Dynamic Programming Algorithm

This contribution is part of Hacktoberfest 2025 🎉

@codecov-commenter
Copy link

codecov-commenter commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.79%. Comparing base (8726d40) to head (a9d7b51).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6789      +/-   ##
============================================
+ Coverage     77.40%   77.79%   +0.38%     
- Complexity     6240     6306      +66     
============================================
  Files           723      728       +5     
  Lines         20839    21011     +172     
  Branches       4064     4096      +32     
============================================
+ Hits          16131    16346     +215     
+ Misses         4075     4021      -54     
- Partials        633      644      +11     

☔ 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.

@Arpita01-work Arpita01-work marked this pull request as ready for review October 15, 2025 16:08
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.

2 participants