🎒 Knapsack Problem: Greedy vs DP

See exactly why the Greedy strategy gets trapped in the 0/1 Knapsack problem.

Available Items (Sorted by Ratio)

Bag Capacity: 10 kg
Item Name Weight (W) Value (V) Ratio (V/W)

✂️ Fractional

✨ Optimal
Algorithm: Greedy

🚫 0/1 Knapsack

⚠️ Suboptimal
Algorithm: Greedy

🎯 0/1 Knapsack

✨ Optimal
Algorithm: DP

💡 Key Takeaway: The Greedy algorithm makes local choices (highest ratio). In Fractional Knapsack, this works perfectly because you can take partial chunks of items to fill the bag without wasting space. However, in 0/1 Knapsack, you can't split items! The Greedy algorithm gets "trapped" taking Item A, which leaves an awkward 3 kg hole that no other items can fill. Dynamic Programming solves this by evaluating all combinations—discovering that entirely skipping the highest-ratio item leaves the perfect amount of room for B and C!