GREEDY ALGORITHMS.
1. A common and useful paradigm for combinatorial algorithms.
Remember the 1980's movie: Wall Street. Michael Douglas says
"Greed is good. Greed is right... Greed works". In this lecture, we
will explore how well and when greed can work for solving computational
or optimization problems.
2. Defining precisely what a greedy algorithm is hard, if not impossible.
In an informal way, an algorithm follows the Greedy Design Principle
if it makes a series of choices, and each choice is "locally optimized";
in other words, when viewed in isolation, that step is performed
optimally.
3. The tricky question is when and why such myopic strategy (looking at each
step individually, and ignoring the global considerations) can still
lead to globally optimal solutions. In fact, when a greedy strategy
leads to an optimal solution, it says something interesting about the
STRUCTURE (nature) of the problem itself! In other cases, even if the
greedy does not give optimal, in many cases it leads to "provably good"
(not too far from optimal) solution.
4. Let us start with a trivial problem, but it will serve to illustrate
the basic idea.
Example: Coin Changing.
US coin denominations:
25, 10, 5, 1
Given an integer x between 0 and 99, make change for x with
least number of coins.
Mathematically, write x = 25a + 10b + 5c + 1d, so that
a+b+c+d is minimum and a,b,c,d >= 0 are ints.
Suggest an algorithm for the coin changing problem.
5. Greedy Coin Changing
Choose as many quarters as possible.
That is, find largest a so that 25a <= x.
Next, choose as many dimes as possible to change x  25a, and so on.
An example. Consider x = 73.
Choose 2 quarters, so a=2.
Remainder: 73  2*25 = 23.
Next, choose 2 dimes, so b=2.
Remainder: 23  2*10 = 3.
Choose 0 nickels, so c=0.
Remainder: 3.
Finally, choose 3 pennies, so d=3.
Reaminder: 33 =0.
Solution is a=2, b=2, c=0, d=3.
Develop a proof that this algorithm always produces change with least number
of coins.
6. Does Greedy Fails Always Work for Coin Changing?
Greedy algorithm's correctness depends on the choice of coins.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
When coins have denominations 25, 10, 5, 1, the greedy always works for any x.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '11
 SURI

Click to edit the document details