GATE Computer ScienceHardGATE CS (PYQ pattern)

Which of the following statements about the 0/1 knapsack problem is/are correct? I. The O(nW) dynamic programme is polynomial in n and in the numeric value W, but not in the number of bits needed to write W. II. If W is encoded in unary, the O(nW) algorithm is polynomial in the input size. III. The fractional knapsack problem is NP-hard. IV. The decision version of 0/1 knapsack is NP-complete.

  1. A. I and III only
  2. B. II and IV only
  3. C. I, II, III and IV
  4. D. I, II and IV only

Correct answer: D. I, II and IV only

I and II describe pseudo-polynomial time precisely (the running time is polynomial in the numeric value). IV is the classical NP-completeness result. III is false: fractional knapsack is solved greedily by value/weight ratio in O(n log n).

More Algorithms questions

Exams that ask this topic