Question
Write a program that solves the knapsack problem recursively in Python for an arbitrary knapsack capacity and series of weights. Assume the weights are sorted
Write a program that solves the knapsack problem recursively in Python for an arbitrary knapsack capacity and series of weights. Assume the weights are sorted in an array.
Hint: The arguments to the knapsack function are target weight and the array index where the remaining items start.
The knapsack problem in its simplest form involves trying to fit items of different weights into a knapsack so that the knapsack ends up with a specified total weight. You need to fit in all items.
For example if you want your knapsack to weigh exactly 20 pounds and you have five items with weights of 11,8,7,6 and 5 pounds. In this case only combination that works is 8, 7 and 5 pounds.
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