1 greedy methods: lecture 1 jose rolim university of geneva

Post on 20-Dec-2015

219 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Greedy methods: Lecture 1

Jose RolimUniversity of Geneva

2007 Algorithmique- Greedy 1

Jose Rolim 2

Reference book

Book:

2007 Algorithmique- Greedy 1

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.

2007 Algorithmique- Greedy 1

Jose Rolim 4

Evaluation

Written Exam No C.C Program Challenge

2007 Algorithmique- Greedy 1

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)

2007 Algorithmique- Greedy 1

Jose Rolim 6

Courses

Monday at Uni-Dufour

Wednesday at Battelle

2007 Algorithmique- Greedy 1

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

2007 Algorithmique- Greedy 1

Jose Rolim 8

Previous examples

BSF DSF

????

2007 Algorithmique- Greedy 1

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

2007 Algorithmique- Greedy 1

Jose Rolim 10

Example 1:

Amount to be returned: 2.89 Coins available:

100 cents 25 cents 10 cents 5 cents 1 cent

2007 Algorithmique- Greedy 1

Jose Rolim 11

Solution

10 coins: 2 dollars 3 quarters 1 dime 4 pennies

2007 Algorithmique- Greedy 1

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???)

2007 Algorithmique- Greedy 1

Jose Rolim 13

Knapsack

2007 Algorithmique- Greedy 1

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

2007 Algorithmique- Greedy 1

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

2007 Algorithmique- Greedy 1

Jose Rolim 16

Example

1020

30

$60 $100 $120

VPP: 6 5 4

Knapsack: hole weight 50

10

20

20--30

2007 Algorithmique- Greedy 1

Jose Rolim 17

Greedy Fails for 0-1 Knapsack

1020

30

$60 $100 $120

VPP: 6 5 410

20

$160

10

30

$180

20

30

$220

2007 Algorithmique- Greedy 1

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.

2007 Algorithmique- Greedy 1

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

2007 Algorithmique- Greedy 1

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

2007 Algorithmique- Greedy 1

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.

top related