Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started