Data Structures & AlgorithmsHardProduct-company MCQ pattern

0/1 knapsack, capacity 7. Items (weight, value): (1, 1), (3, 4), (4, 5), (5, 7). What is the maximum total value?

  1. A. 8
  2. B. 17
  3. C. 9
  4. D. 12

Correct answer: C. 9

Weights 3 + 4 = 7 give 4 + 5 = 9, the best fit; 5 + 1 gives only 8. Ratio-greedy takes (5, 7) then (1, 1) for 8, adding every item ignores the capacity (17), and the two most valuable items (7 + 5 = 12) weigh 9.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic