Skip to content

Conversation

@Arpita01-work
Copy link
Contributor

@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 78.91%. Comparing base (d382e65) to head (8e5078b).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6789      +/-   ##
============================================
- Coverage     78.92%   78.91%   -0.01%     
+ Complexity     6884     6883       -1     
============================================
  Files           774      774              
  Lines         22747    22746       -1     
  Branches       4469     4468       -1     
============================================
- Hits          17952    17949       -3     
- Misses         4076     4077       +1     
- Partials        719      720       +1     

☔ 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
@DenizAltunkapan DenizAltunkapan merged commit 35556fe into TheAlgorithms:master Dec 29, 2025
7 checks passed
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.

3 participants