This preview shows pages 1–12. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 473: Algorithms Chandra Chekuri chekuri@cs.illinois.edu 3228 Siebel Center University of Illinois, UrbanaChampaign Fall 2009 Chekuri CS473ug Knapsack Part I Knapsack Chekuri CS473ug Knapsack Knapsack Problem Input Given a Knapsack of capacity W lbs. and n objects with i th object having weight w i and value v i ; assume W , w i , v i are all positive integers Goal Fill the Knapsack without exceeding weight limit while maximizing value. Chekuri CS473ug Knapsack Knapsack Problem Input Given a Knapsack of capacity W lbs. and n objects with i th object having weight w i and value v i ; assume W , w i , v i are all positive integers Goal Fill the Knapsack without exceeding weight limit while maximizing value. We saw that: Knapsack can be solved exactly in O ( nW ) time via dynamic programming. Not polynomial time when W is large compared to n . Knapsack is NPComplete Chekuri CS473ug Knapsack Knapsack Example Example Item 1 2 3 4 5 Value 1 6 18 22 28 Weight 1 2 5 6 7 If W = 11, the best is { 3 , 4 } giving value 40. Chekuri CS473ug Knapsack Greedy Approximation Algorithm Sort objects in decreasing order of v i / w i (bang per buck) Chekuri CS473ug Knapsack Greedy Approximation Algorithm Sort objects in decreasing order of v i / w i (bang per buck) Insert items in sorted order and item to knapsack if sufficient weight left. Chekuri CS473ug Knapsack Greedy Approximation Algorithm Sort objects in decreasing order of v i / w i (bang per buck) Insert items in sorted order and item to knapsack if sufficient weight left. Bad example: Two items: v 1 = 1, w 1 = 1, v 2 = W 1, w 2 = W . Greedy will pack item 1 and stop and get value 1 while optimum solution is to pack item 2 of value W 1. Chekuri CS473ug Knapsack Greedy Approximation Algorithm Sort objects in decreasing order of v i / w i (bang per buck) Insert items in sorted order and item to knapsack if sufficient weight left. Bad example: Two items: v 1 = 1, w 1 = 1, v 2 = W 1, w 2 = W . Greedy will pack item 1 and stop and get value 1 while optimum solution is to pack item 2 of value W 1. Chekuri CS473ug Knapsack Greedy Approximation Algorithm Sort objects in decreasing order of v i / w i (bang per buck) Insert items in sorted order and item to knapsack if sufficient weight left. Bad example: Two items: v 1 = 1, w 1 = 1, v 2 = W 1, w 2 = W . Greedy will pack item 1 and stop and get value 1 while optimum solution is to pack item 2 of value W 1. Is Greedy really bad? Chekuri CS473ug Knapsack Greedy Approximation Algorithm Sort objects in decreasing order of v i / w i (bang per buck) Insert items in sorted order and item to knapsack if sufficient weight left. Bad example: Two items: v 1 = 1, w 1 = 1, v 2 = W 1, w 2 = W . Greedy will pack item 1 and stop and get value 1 while optimum solution is to pack item 2 of value W 1....
View Full
Document
 Fall '08
 Chekuri,C
 Algorithms

Click to edit the document details