








































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









































































Mahesh Viswanathan [email protected] 3232 Siebel Center
University of Illinois, Urbana-Champaign
Spring 2008
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Input Given a Knapsack of capacity W lbs. and n objects with ith object having weight wi and value vi
Goal Fill the Knapsack without exceeding weight limit while maximizing value.
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Input Given a Knapsack of capacity W lbs. and n objects with ith object having weight wi and value vi ; assume W , wi , vi are all positive integers Goal Fill the Knapsack without exceeding weight limit while maximizing value.
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
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.
Special Case When vi = wi , the Knapsack problem is called the Subset Sum Problem.
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Application to Scheduling Knapsack interpreted as a single machine, objects as jobs to be scheduled, weights as processing times, and values as priorities.
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Pick objects with greatest value Let W = 2, w 1 = w 2 = 1, w 3 = 2, v 1 = v 2 = 2 and v 3 = 3; greedy strategy will pick { 3 }, but the optimal is { 1 , 2 }
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Pick objects with greatest value Let W = 2, w 1 = w 2 = 1, w 3 = 2, v 1 = v 2 = 2 and v 3 = 3; greedy strategy will pick { 3 }, but the optimal is { 1 , 2 } Pick objects with smallest weight
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Pick objects with greatest value Let W = 2, w 1 = w 2 = 1, w 3 = 2, v 1 = v 2 = 2 and v 3 = 3; greedy strategy will pick { 3 }, but the optimal is { 1 , 2 } Pick objects with smallest weight Let W = 2, w 1 = 1, w 2 = 2, v 1 = 1 and v 2 = 3; greedy strategy will pick { 1 }, but the optimal is { 2 } Pick objects with largest vi /wi ratio
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Pick objects with greatest value Let W = 2, w 1 = w 2 = 1, w 3 = 2, v 1 = v 2 = 2 and v 3 = 3; greedy strategy will pick { 3 }, but the optimal is { 1 , 2 } Pick objects with smallest weight Let W = 2, w 1 = 1, w 2 = 2, v 1 = 1 and v 2 = 3; greedy strategy will pick { 1 }, but the optimal is { 2 } Pick objects with largest vi /wi ratio Let W = 4, w 1 = w 2 = 2, w 3 = 3, v 1 = v 2 = 3 and v 3 = 5; greedy strategy will pick { 3 }, but the optimal is { 1 , 2 }
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Let Opt(i) be maximum value obtained for items 1,... i Case n is not selected.
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Let Opt(i) be maximum value obtained for items 1,... i Case n is not selected. The optimal choice is the optimal choice of the first 1 though n − 1 items, i.e., Opt(n − 1)
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Let Opt(i) be maximum value obtained for items 1,... i Case n is not selected. The optimal choice is the optimal choice of the first 1 though n − 1 items, i.e., Opt(n − 1) Case n is selected. Need to pick items from 1 through n − 1 that leaves room for item n
Shortest Paths in GraphsKnapsack Detecting Negative CyclesNetwork Routing Greedy AttemptDynamic Programming Solution
Let Opt(i) be maximum value obtained for items 1,... i Case n is not selected. The optimal choice is the optimal choice of the first 1 though n − 1 items, i.e., Opt(n − 1) Case n is selected. Need to pick items from 1 through n − 1 that leaves room for item n Need more subproblems.