Question: Problem 2 . You are given n items, each with a weight w i and a value v i . Your goal is to fill
Problem You are given items, each with a weight and a value Your goal is
to fill a knapsack of capacity to maximize the total value. Unlike the discrete
knapsack problem, in which you must take whole items a classic dynamic programming
problem that you can try for extra practice you can now take fractions of items.
a points Write a greedy algorithm in pseudocode that will select items to max
imize the total value of the knapsack. Explain how your algorithm works.
b points Prove that your proposed greedy algorithm provides an optimal solution.
You may assume that the ratio is distinct for each item.
c points How does this problem differ from the knapsack problem, and why
does the greedy strategy fail for the case? Hint: consider how taking a fractional
amount of an item in the fractional knapsack problem might benefit the greedy
approach, but is not allowed in the knapsack problem.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
