0% found this document useful (0 votes)
14 views11 pages

Lecture 4

The document discusses greedy algorithms and provides examples of the counting money problem and job scheduling problem. It explains that greedy algorithms make locally optimal choices at each step but do not always lead to a globally optimal solution.

Uploaded by

Mary.S.V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

Lecture 4

The document discusses greedy algorithms and provides examples of the counting money problem and job scheduling problem. It explains that greedy algorithms make locally optimal choices at each step but do not always lead to a globally optimal solution.

Uploaded by

Mary.S.V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CSEN 707: Analysis and Design of

Algorithms

Greedy Algorithms

Slides derived from Dr. Wael Abulsadat lecture notes CSEN 707 Winter 2016
Greedy Algorithms
For an optimization problem maximize (or minimize)

 At any step of the greedy algorithm there are a set of


choices

 The greedy method will aggressively pursue the choice


that seems to currently fit most the objective function

2
Counting Money Problem
 The problem is to count a certain amount of
money, using the fewest possible bills and coins
(after all who wants to carry too much change in
his pockets)
 Available bills and coins
1¢ , 10¢ , 25¢ , $1 , $5, $10, $20, $50, $100

 E.g. How to make $7.47 using the fewest possible


bills and coins?

3
Counting Money Problem
 The greedy approach select the highest bill/coin
that would not lead to exceeding the desired
amount of money (the intuition is that this should
decrease the number of bills/coins required)
 Available bills and coins
1¢ , 10¢ , 25¢ , $1 , $5, $10, $20, $50, $100,
Desired $7.47
 $5+$1+$1+25¢+10¢ +10¢+1¢ +1¢
 Eights bills and coins

4
Counting Money Problem
 Assume a hypothetical monetary system with bills
of 1, 7, 10
 How to count 15 from these bills
 Greedy Method 10+1+1+1+1+1 (Six bills)

 NOT OPTIMAL
 An OPTIMAL solution is 7+7+1 (Three bills)

5
Optimality of the Greedy Method
 The greedy method does not necessary lead to
the optimal solution

 The greedy method selects at each step the choice that


seems to be currently the best

 The best instantaneous choice (local choice) does not


necessarily lead to the global optimal solution

6
Scheduling Problem
 You have to run nine jobs, with running times of
 3, 5, 6, 10, 11, 14, 15, 18, and 20 minutes
 You have 3 processors on which you can run
these jobs

7
Scheduling Problem
 Two choices we need to make
 Which is the next job to schedule and
 Which processor to assign this job to

 Options for job sequence


 Descending from Longest-to-Shortest
 Ascending from Shortest-to-Longest

 For the processor assignment, the greedy method entails


the selection of the processor that will minimize the
maximum finishing time among the three processors (i.e.,
the processor currently finishing the earliest)

8
Longest-to-Shortest Job Sequence
 20, 18, 15, 14, 11, 10, 6 , 5, 3

20 10 3

18 11 5

15 14 6

Sol=36

9
Shortest-to-Longest Job Sequence
 3, 5, 6, 10, 11, 14, 15, 18, 20

3 10 15

5 11 18

6 14 20

Sol=40

10
Optimal Solution
 3, 5, 6, 10, 11, 14, 15, 18, 20

20 14

18 11 5

15 10 6 3

Sol=34

Not necessarily attainable by the Greedy Method

11

You might also like