1 / 21

Greedy methods: Lecture 1

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. .

kina
Download Presentation

Greedy methods: Lecture 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Reference book • Book: Jose Rolim

  3. 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

  4. Evaluation • Written Exam • No C.C • Program Challenge Jose Rolim

  5. 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

  6. Courses • Monday at Uni-Dufour • Wednesday at Battelle Jose Rolim

  7. 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

  8. Previous examples • BSF • DSF • ???? Jose Rolim

  9. 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

  10. Example 1: • Amount to be returned: 2.89 • Coins available: • 100 cents • 25 cents • 10 cents • 5 cents • 1 cent Jose Rolim

  11. Solution • 10 coins: • 2 dollars • 3 quarters • 1 dime • 4 pennies Jose Rolim

  12. 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

  13. Knapsack Jose Rolim

  14. 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

  15. 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

  16. 20 -- 30 20 10 Example 30 Knapsack: hole weight 50 20 10 $60 $100 $120 VPP: 6 5 4 Jose Rolim

  17. 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

  18. 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

  19. 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

  20. 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

  21. 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

More Related