This preview shows page 1. Sign up to view the full content.
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
This note was uploaded on 02/12/2014 for the course CS 475 taught by Professor Staff during the Fall '08 term at Colorado State.
 Fall '08
 Staff

Click to edit the document details