Lec4Knapsack

# Take best of 1 2 i 1 using weight limit w opti 1w

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ave optimal substructure. !   Travelling Salesman Problem (TSP)? Knapsack Problem ! ! ! !         Given n objects and a "knapsack” of capacity W Item i has a weight wi > 0 and value vi > 0. Goal: ﬁll knapsack so as to maximize total value. Is there a Greedy solution? !   What’s Greedy again? !   What would it do here? repeatedly add item with maximum vi / wi ratio … Does Greedy work? Capacity M = 7, Number of objects n = 3 w = [5, 4, 3] v = [10, 7, 5] (ordered by vi / wi ratio) Recursion for Knapsack Problem !   Notation: OPT(i, W) = optimal value of max weight subset that uses items 1, …, i with weight limit W. !   Case 1: item i is not included: !   Take best of { 1, 2, …, i- 1 } using weight limit W : OPT(i- 1,W) !   Case 2: item i with weigh wi and value vi is included: !   only possible if W >= wi !   new weight limit = W – wi !   Take best...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern