Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Greedy methods: Lecture 1 Jose Rolim University of Geneva.

Similar presentations


Presentation on theme: "1 Greedy methods: Lecture 1 Jose Rolim University of Geneva."— Presentation transcript:

1 1 Greedy methods: Lecture 1 Jose Rolim University of Geneva

2 2007 Algorithmique- Greedy 1 Jose Rolim2 Reference book  Book:

3 2007 Algorithmique- Greedy 1 Jose Rolim3 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.

4 2007 Algorithmique- Greedy 1 Jose Rolim4 Evaluation  Written Exam  No C.C  Program Challenge

5 2007 Algorithmique- Greedy 1 Jose Rolim5 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)

6 2007 Algorithmique- Greedy 1 Jose Rolim6 Courses  Monday at Uni-Dufour  Wednesday at Battelle

7 2007 Algorithmique- Greedy 1 Jose Rolim7 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

8 2007 Algorithmique- Greedy 1 Jose Rolim8 Previous examples  BSF  DSF  ????

9 2007 Algorithmique- Greedy 1 Jose Rolim9 Ex: Making changes  A dollar amount to reach and a collection of coins amount to get there  PROBLEM:  Minimize the number of coins returned

10 2007 Algorithmique- Greedy 1 Jose Rolim10 Example 1:  Amount to be returned: 2.89  Coins available:  100 cents  25 cents  10 cents  5 cents  1 cent

11 2007 Algorithmique- Greedy 1 Jose Rolim11 Solution  10 coins:  2 dollars  3 quarters  1 dime  4 pennies

12 2007 Algorithmique- Greedy 1 Jose Rolim12 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???)

13 2007 Algorithmique- Greedy 1 Jose Rolim13 Knapsack

14 2007 Algorithmique- Greedy 1 Jose Rolim14 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

15 2007 Algorithmique- Greedy 1 Jose Rolim15 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

16 2007 Algorithmique- Greedy 1 Jose Rolim16 Example 10 20 30 $60$100$120 VPP:654 Knapsack: hole weight 50 10 20 -- 30

17 2007 Algorithmique- Greedy 1 Jose Rolim17 Greedy Fails for 0-1 Knapsack 10 20 30 $60$100$120 VPP:654 10 20 $160 10 30 $180 20 30 $220

18 2007 Algorithmique- Greedy 1 Jose Rolim18 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.

19 2007 Algorithmique- Greedy 1 Jose Rolim19 Example  There are 6 tasks, with start times and finishing times (1,3), (2,5), (2,6), (4,5), (5,8), (5,7).

20 2007 Algorithmique- Greedy 1 Jose Rolim20 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

21 2007 Algorithmique- Greedy 1 Jose Rolim21 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.


Download ppt "1 Greedy methods: Lecture 1 Jose Rolim University of Geneva."

Similar presentations


Ads by Google