Question: Please explain the python code step by step . And knapsack is P or NP ? And give an input ,output and list content after
Please explain the python code step by step . And knapsack is P or NP ? And give an input ,output and list content after calling the function. Thanks in advance!
def knapsack(w,v,c):
items = []
while len(v)>0 :
value = max(v)
index = v.index(value)
if c-w[index]>=0:
items +=[[w[index],value]]
c -= w[index]
v.pop(index)
w.pop(index)
return items
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
