Questions: 0/1 Knapsack Problem: Bounded Capacity DP

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A knapsack has capacity 10. Three items are available: Item A (weight=6, value=8), Item B (weight=5, value=5), Item C (weight=5, value=5). A greedy algorithm selects items by highest value-to-weight ratio first. What does the greedy algorithm choose, and what is the optimal selection?

AGreedy: Item A (value=8); Optimal: Items B and C (value=10)
BGreedy: Items B and C (value=10); Optimal: Item A (value=8)
CGreedy: Item A (value=8); Optimal: Item A (value=8)
DGreedy: Items B and C (value=10); Optimal: Items B and C (value=10)
Question 2 Multiple Choice

After filling a 2D dp[n][W] table for the 0/1 knapsack, how do you determine which items were included in the optimal solution?

ASelect the n items whose individual values appear in the dp table cells
BTrace backward from dp[n][W]: if dp[i][w] ≠ dp[i-1][w], item i was included; move to dp[i-1][w - weight_i]
CRe-run the greedy algorithm on the items sorted by their DP-table contributions
DRead the items off the final row of the table in left-to-right order
Question 3 True / False

The 1D (space-optimized) version of the 0/1 knapsack DP requires iterating through capacity values in decreasing order (from W down to weight_i) when processing each item.

TTrue
FFalse
Question 4 True / False

Since the 0/1 knapsack DP runs in O(nW) time, it is a polynomial-time algorithm and can efficiently handle any input, including cases where W is a 100-digit number.

TTrue
FFalse
Question 5 Short Answer

Why does the 0/1 knapsack problem require dynamic programming rather than a greedy approach, and what property of the problem makes greedy fail?

Think about your answer, then reveal below.