greedy(meta-algo III)

Every two years old knows the greedy algorithm.

In order to get what you want, just start grabbing what looks best.

Surprisingly, many important and practical computational problems can be solved this way.

Ingredients:

the possible inputs to the problem.

each instance has an exponentially large set of solutions.

the brute force algorithm:

try every solution! exponentially time, because exponentially many.

The greedy choice:

commit to the object that looks the best.

must prove that this locally greedy choice does not have negative global consequences.

but greedy algorithms do not try to predict the future and do not back track.

 

problem: find the minimum # of 4,3, and 1 cent coins to make up 6 cents.

Greedy choice: start by grabbing a 4 coin.

consequences:

4 +1 +1 =6  mistake

3 +3 better

greedy algorithm does not work.

 

greedy algorithm : easy to understand and to code, but do they work?

for most optimization problems, all greedy problems tried do not work.

a few have greedy algorithms, the proof that they work, however, is subtle.

loop invariant:

recall that a loop invariant makes a statement each time the algorithm is at the top of the loop about what it has accomplished.

after the algorithm has committed to one object, what statement do we want to make about this action?

the algorithm's solution is optimal.

The algorithm has only committed to one object and this does not constitute a valid solution.

what the algorithm has done so far is optimal.

being optimal is a property of full solutions.

"more of the input", this kind of loop invariant is hard to extend from partial instances to full instances.

It is ok to burn a few of your bridges as long as you do not burn all of them. :)

...

but, this way only for the first iteration. :(

St extends At

 If At makes a decision about an object, the St makes the same decision.

 What other decisions St makes is unknown to the algorithm and to the prover.

So,

in the t+1 th time steps, the algorithm A(t+1)decides about the next "best" object.

St extends A(t+1). !!!

This "bridge" has been burned!

loop invariant:

we have not gone wrong.

there is at least one optimal solution St+1 that extends the choices At+1 made so far.

if there are no optimal solutions that extends the choices made so far, we went wrong.

 Schedule problem:

greedy criteria: earliest finishing time

motivation: schedule the event which will free up your room for someone else as soon as possible.

 

 

posted on 2012-05-13 10:35  grep  阅读(268)  评论(0编辑  收藏  举报