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 2. You are given n items, each with a weight wi and a value vi. Your goal is
to fill a knapsack of capacity W to maximize the total value. Unlike the discrete (01)
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)(10 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)(10 points) Prove that your proposed greedy algorithm provides an optimal solution.
You may assume that the ratio viwi is distinct for each item.
c)(10 points) How does this problem differ from the 01 knapsack problem, and why
does the greedy strategy fail for the 01 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 01 knapsack problem.)
Problem 2 . You are given n items, each with a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!