Data Structures & AlgorithmsHardGATE CS

0/1 knapsack with capacity 27: weights [13, 8, 9, 14, 12, 4, 11] and values [25, 19, 16, 27, 22, 8, 23] (item i has weight w[i] and value v[i]). What is the maximum total value?

  1. A. 50
  2. B. 54
  3. C. 52
  4. D. 57

Correct answer: B. 54

Exhaustive search/DP gives 54. Greedy by value-to-weight ratio picks items worth only 50, and greedy by value gives 52; neither is optimal for 0/1 items.

More Coding Interview Problems questions

Exams that ask this topic