A thief robbing a store finds n items. The item is worth vi dollars and weighs w pounds, where v; and wi are integers. The thief wants to take as valuable a load as possible, but he can carry at most W pounds in his knapsack, for some integer W. Which items should he take? This problem is called 0-1 knapsack problem because for each item, the thief either take it or leave behind. No fractional amount from an item can be taken. Consider the most valuable load that weighs at most W pounds. If we remove item j from this load, the remaining load must be the most valuable load weighing at most W-w; that the thief can take from the n-I original items excluding j. Write a simple pseudo code for the given greedy algorithm description first and show how using this greedy algorithm to solve the problem of Knapsack problem below. Assume that maximum weight that can be carried is 7 lbs. Does it your code find the optimal solution? Show the optimal solution if it exists. 1 2 3 4 3 10 15 5 3 Item Value (S) 20 Weight (lb) 5 1 5 4 4
A thief robbing a store finds n items. The item is worth vi dollars and weighs w pounds, where v; and wi are integers. The thief wants to take as valuable a load as possible, but he can carry at most W pounds in his knapsack, for some integer W. Which items should he take? This problem is called 0-1 knapsack problem because for each item, the thief either take it or leave behind. No fractional amount from an item can be taken. Consider the most valuable load that weighs at most W pounds. If we remove item j from this load, the remaining load must be the most valuable load weighing at most W-w; that the thief can take from the n-I original items excluding j. Write a simple pseudo code for the given greedy algorithm description first and show how using this greedy algorithm to solve the problem of Knapsack problem below. Assume that maximum weight that can be carried is 7 lbs. Does it your code find the optimal solution? Show the optimal solution if it exists. 1 2 3 4 3 10 15 5 3 Item Value (S) 20 Weight (lb) 5 1 5 4 4
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps