Knapsack Problem Variants (0/1, Fractional, Bounded, Unbounded)

viaGlassdoor

Problem: Explain and solve all forms of the Knapsack problem - 0/1, Fractional, Bounded, and Unbounded. Constraints: Given item weights, values, and a capacity limit, maximize total value without exceeding capacity, under each variant's rules on how many of each item can be taken. Approach: 0/1 Knapsack - each item taken at most once, solved via DP over (items x capacity). Fractional Knapsack - items divisible, greedy by value/weight ratio gives optimal solution. Bounded Knapsack - each item has a limited count, solved via DP with a bounded count dimension (or binary splitting to reduce to 0/1). Unbounded Knapsack - unlimited copies of each item, solved via DP where each capacity state can reuse the same item multiple times.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account