Question: Consider a variant of knapsack problem where the objective is to select from a list of items with infinite supply while obeying capacity limitations .
Consider a variant of knapsack problem where the objective is to select from a list
of items with infinite supply while obeying capacity limitations For instance, let values weights and
capacity Then the optimal value is and solution in dictionary format is : : ie use of item and of item
a Implement a greedy algorithm that first ranks the items based on their value per weight ratios ie viwi then puts the
maximum number of items with the best ratio into the knapsack, and move to the next items according to the ratio until the
knapsack is filled. For instance, in the above example, ratios so we first include of item then include
of item since the remaining capacity after including of item is Sample function call and expected inputsoutputs
are provided below.
# inputs are identical to the ones provided in the problem description
totalvalue, selecteditems knapsackextensiongreedyvalues weights, capacity
# totalvalue selecteditems: : output sorted dictionary based on keys code in python
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
