Question: 2 . 1 Problem 3 [ 1 5 p t s ] Problem 3 . Consider the Knapsack problem with the following inputs: A list

2.1 Problem 3[15pts]
Problem 3. Consider the Knapsack problem with the following inputs:
A list of items: (v1,w1),dots,(vn,wn), where vi is the value and wi is the weight of the i-th item.
A weight limit W.
The goal is to select a subset Ssube{1,dots,n} such that:
iinS?wiW
maximizes the total value:
V=iinS?vi
Consider the following greedy algorithm for this problem:
Order the items by their value-per-weight ratio, viwi, in descending order.
Select items in this order, adding them to S as long as the total weight remains within the limit W.
Provide an example demonstrating that this greedy algorithm does not always yield the optimal solution.
Include the example, show the steps of the greedy algorithm on it, and present a solution with a higher total value
that adheres to the weight limit.
2 . 1 Problem 3 [ 1 5 p t s ] Problem 3 .

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!