Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] <title>Add Knapsack Algorithm in Java (Dynamic Programming) [Hactoberfest]

Open Dhanyasri7 opened this issue 1 month ago • 3 comments

What would you like to Propose?

This issue is created as part of Hacktoberfest 2025. I would like to propose adding the 0/1 Knapsack Algorithm implemented in Java using Dynamic Programming.

This algorithm helps solve optimization problems where we must select items with given weights and values to maximize total value within a limited capacity. It’s one of the most fundamental examples of dynamic programming and is highly useful for learners exploring algorithmic problem-solving in Java.

Issue details

🧮 Algorithm Name

0/1 Knapsack Problem (Dynamic Programming)

📖 Problem Statement

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

💡 Example

Input: values = {60, 100, 120} weights = {10, 20, 30} W = 50

Output: Maximum value = 220

🧰 Language

Java

🔗 Proposed File Path

DynamicProgramming/Knapsack.java

📦 Proposed Implementation

  • Use a bottom-up dynamic programming approach.
  • Include clear comments and clean variable names.
  • Add a main() method with example input/output for testing.

Additional Information

No response

Dhanyasri7 avatar Oct 14 '25 00:10 Dhanyasri7