Lec25_Knapsack - Knapsack Problem Greedy Approach VS...

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

View Full Document Right Arrow Icon
Knapsack Problem
Background image of page 1

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

View Full DocumentRight Arrow Icon
Greedy Approach VS Dynamic Programming (DP) Comparing the methods Knapsack problem Greedy algorithms for 0/1 knapsack An approximation algorithm for 0/1 knapsack Optimal greedy algorithm for knapsack with fractions A dynamic programming algorithm for 0/1 knapsack
Background image of page 2
Greedy Approach VS Dynamic Programming (DP) Greedy and Dynamic Programming are methods for solving optimization problems. Greedy algorithms are usually more efficient than DP solutions. However, it is quite often that you need to use dynamic programming since the optimal solution cannot be guaranteed by a greedy algorithm. DP provides efficient solutions for some problems for which a brute force approach would be very slow. To use Dynamic Programming we need only show that the principle of optimality applies to the problem.
Background image of page 3

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

View Full DocumentRight Arrow Icon
The 0/1 Knapsack problem Given a knapsack with weight W > 0 . A set S of n items with weights w i > 0 and benefits b i > 0 for i = 1,…, n . S = { ( item 1 , w 1 , b 1 ), ( item 2 , w 2 , b 2 ) , . . . , ( item n, w n , b n ) } Find a subset of the items which does not exceed the weight W of the knapsack and maximizes the benefit.
Background image of page 4
Determine a subset A of { 1, 2, …, n } that satisfies the following: In 0/1 knapsack a specific item is either selected or not A i i A i i W w b where max 0/1 Knapsack problem
Background image of page 5

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

View Full DocumentRight Arrow Icon
Variations of the Knapsack problem Fractions are allowed. This applies to items such as: bread, for which taking half a loaf makes sense gold dust No fractions. 0/1 (1 brown pants, 1 green shirt…) Allows putting many items of same type in knapsack 5 pairs of socks 10 gold bricks More than one knapsack, etc.
Background image of page 6
Brute force! Generate all 2 n subsets Discard all subsets whose sum of the weights exceed W (not feasible) Select the maximum total benefit of the remaining (feasible) subsets What is the run time? O( n 2 n )
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example with “brute force” S = { ( item 1 , 5, $70 ), ( item 2 ,10, $90 ), ( item 3 , 25, $140 ) } , W=25 Subsets: 1. {} 2. { ( item 1 , 5, $70 ) } Profit=$70 3. { ( item 2 ,10, $90 ) } Profit=$90 4. { ( item 3 , 25, $140 ) } Profit=$140 5. { ( item 1 , 5, $70 ), ( item 2 ,10, $90 )}. Profit=$160 **** 6. { ( item 2 ,10, $90 ), ( item 3 , 25, $140 ) } exceeds W 7. { ( item 1 , 5, $70 ), ( item 3 , 25, $140 ) } exceeds W 8. { ( item 1 , 5, $70 ), ( item 2 ,10, $90 ), ( item 3 , 25, $140 ) }
Background image of page 8
Greedy 1: Selection criteria: Maximum beneficial item. Counter Example: S = { ( item 1 , 5, $70 ), ( item 2 ,10, $90 ), ( item 3 , 25, $140 ) } 5 lb $70 10 lb $90 $140 W = 25lb 25 lb item 1 item 2 item 3 Knapsack Greedy Solution 25 lb $140 Optimal Solution 10 lb 5 lb $70 10 lb $90 =$140 =$160
Background image of page 9

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

View Full DocumentRight Arrow Icon
Greedy 2: Selection criteria: Minimum weight item Counter Example: S = { ( item 1 , 5, $150 ), ( item 2 ,10, $60 ), ( item 3 , 20, $140 ) } 5 lb $150 10 lb $60 $140 W = 30lb 20 lb item 1 item 2 item 3 Knapsack Greedy Solution 5 lb 5 lb 20 lb $150 $140 5 lb 10 lb $60 $150 Optimal Solution =$210 =$290
Background image of page 10
Greedy 3: Selection criteria: Maximum weight
Background image of page 11

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

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

This document was uploaded on 01/04/2010.

Page1 / 31

Lec25_Knapsack - Knapsack Problem Greedy Approach VS...

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