- GATE CS
- 2026–27 pattern practice
- Algorithms
- Dynamic programming
- Easy
The standard dynamic-programming solution to 0/1 knapsack with n items and capacity W runs in
Algorithm Design
Pick an option to check your answer.
Answer: D. Solution
The DP table has cells, each filled in , giving . Because is a number whose input size is only bits, this is pseudo-polynomial, not polynomial — 0/1 knapsack remains NP-hard.
Why not the others
- is the greedy fractional knapsack, which sorts by value/weight.
- always is brute force; the DP avoids it.
- , which is polynomial — the bound depends on , not just .