210 likes | 521 Views
Greedy methods: Lecture 1. Jose Rolim University of Geneva. Reference book. Book:. Also:. Brassard, Gilles et Bratley, Paul. Fundamentals of Algorithmics , Prentice-Hall. ISBN : 0-13-335068-1 E. Horowitz, S. Sahni, and S. Rajasekaran. Computer Algorithms . W. H. Freeman Press, 1997. .
E N D
Greedy methods: Lecture 1 Jose Rolim University of Geneva
Reference book • Book: Jose Rolim
Also: • Brassard, Gilles et Bratley, Paul. Fundamentals of Algorithmics, Prentice-Hall. ISBN : 0-13-335068-1 • E. Horowitz, S. Sahni, and S. Rajasekaran. Computer Algorithms. W. H. Freeman Press, 1997. Jose Rolim
Evaluation • Written Exam • No C.C • Program Challenge Jose Rolim
Program • Greedy – JR (2 weeks) • Divide and Conquer – BC (2 weeks) • Dynamic Programming – JR (2 weeks) • Backtracking – BC (2 weeks) • Advanced Graph Algorithms – JR (2 weeks) • Branch and Bound – BC (2 weeks) Jose Rolim
Courses • Monday at Uni-Dufour • Wednesday at Battelle Jose Rolim
Greedy - Principles • Optimization problem • Best choice at any moment • Basic steps: • Define the problem and corresponding greedy strategy • Show that greedy approach leads to optimal solution Jose Rolim
Previous examples • BSF • DSF • ???? Jose Rolim
Ex: Making changes • A dollar amount to reach and a collection of coins amount to get there • PROBLEM: • Minimize the number of coins returned Jose Rolim
Example 1: • Amount to be returned: 2.89 • Coins available: • 100 cents • 25 cents • 10 cents • 5 cents • 1 cent Jose Rolim
Solution • 10 coins: • 2 dollars • 3 quarters • 1 dime • 4 pennies Jose Rolim
Greedy strategy • At every stage add a coin of the largest possible value that does not pass the amount to be paid • Does the greed strategy always work???? • YES. For this set of coins • NOT NECESSARLY for another set (EX???) Jose Rolim
Knapsack Jose Rolim
Knapsack • 0-1 knapsack problem: • How to fill the knapsack with best total value w/o breaking each item • Fractional knapsack problem: • How to fill the knapsack with best total value Jose Rolim
Solutions ???? • NP- hard for 0-1 knapsack • Greedy for fractional knapsack • Compute value per pound (VPP) for each item • Take as much as possible of the item with largest VPP • Continue till reach weight limit Jose Rolim
20 -- 30 20 10 Example 30 Knapsack: hole weight 50 20 10 $60 $100 $120 VPP: 6 5 4 Jose Rolim
30 30 20 20 10 10 $180 $220 $160 Greedy Fails for 0-1 Knapsack 30 20 10 $60 $100 $120 VPP: 6 5 4 Jose Rolim
Task scheduling problem • We have a set T of N tasks, each with a start time si and a finishing time fi (si<fi). • Each task must start at time si and will finish at time fi. • Each task is executed on a machine Mj. • A machine can execute only one task at a time, but can start a task at the same time as the current task ends (red lines on the figure to the right). • Tasks are non-conflicting if they do not conflict, i.e., if fi≤sj or fj≤si. For example, think of tasks as classes. • The problem is to schedule all the tasks in T using the minimal number of machines. Jose Rolim
Example • There are 6 tasks, with start times and finishing times (1,3), (2,5), (2,6), (4,5), (5,8), (5,7). Jose Rolim
Greedy strategy • In our greedy strategy we only go to a new machine when we find a task that cannot be scheduled on the current machines Jose Rolim
In the example • They are scheduled on three machines M1, M2, M3. • Clearly 3 machines are needed as can be seen by looking at time 4. Jose Rolim