lecture23 - CS 473: Algorithms Chandra Chekuri...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 473: Algorithms Chandra Chekuri chekuri@cs.illinois.edu 3228 Siebel Center University of Illinois, Urbana-Champaign 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 NP-Complete 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

Page1 / 104

lecture23 - CS 473: Algorithms Chandra Chekuri...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online