Data Structures & AlgorithmsModerateCognizant · Capgemini pattern

Why does the greedy method (best value-per-weight first) solve the fractional knapsack problem but not the 0/1 knapsack problem?

  1. A. Because sorting by ratio takes too long for 0/1 knapsack
  2. B. Because fractional knapsack has fewer items
  3. C. Because 0/1 knapsack has negative weights
  4. D. Because in 0/1 knapsack an item cannot be split, so leftover capacity may be wasted

Correct answer: D. Because in 0/1 knapsack an item cannot be split, so leftover capacity may be wasted

With fractions the last item can always be cut to fill the bag exactly. With whole items only, taking the best-ratio item can leave unusable space, so 0/1 knapsack needs dynamic programming.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic