04.09.2013 Views

Algorithm Design

Algorithm Design

Algorithm Design

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

180<br />

Chapter 4 Greedy <strong>Algorithm</strong>s<br />

the other edges out of r. This kind of argument never clouded our thinking in<br />

the Minimum Spanning Tree Problem, where it was always safe to plunge<br />

ahead and include the cheapest edge; it suggests that finding the optimal<br />

arborescence may be a significantly more complicated task. (It’s worth noticing<br />

that the optimal arborescence in Figure 4.19 also includes the most expensive<br />

edge on a cycle; with a different construction, one can even cause the optimal<br />

arborescence to include the most expensive edge in the whole graph.)<br />

Despite this, it is possible to design a greedy type of algorithm for this<br />

problem; it’s just that our myopic rule for choosing edges has to be a little<br />

more sophisticated. First let’s consider a little more carefully what goes wrong<br />

with the general strategy of including the cheapest edges. Here’s a particular<br />

version of this strategy: for each node v # r, select the cheapest edge entering<br />

v (breaking ties arbitrarily), and let F* be this set of n - 1 edges. Now consider<br />

the subgraph (V, F*). Since we know that the optimal arborescence needs to<br />

have exactly one edge entering each node v # r, and (V, F*) represents the<br />

cheapest possible way of making these choices, we have the following fact2<br />

(4.36) I[ (V, F*) is an arborescence, then it is a minimum-cost arborescence.<br />

So the difficulty is that (V, F*) may not be an arborescence. In this case,<br />

(4.34) implies that (V, F*) must contain a cycle C, which does not include the<br />

root. We now must decide how to proceed in this situation.<br />

To make matters somewhat clearer, we begin with the following observation.<br />

Every arborescence contains exactly one edge entering each node v # r;<br />

so if we pick some node v and subtract a uniform quantity from the cost of<br />

every edge entering v, then the total cost of every arborescence changes by<br />

exactly the same amount. This means, essentially, that the actual cost of the<br />

cheapest edge entering v is not important; what matters is the cost of all other<br />

edges entering v relative to this. Thus let Yv denote the minimum cogt of any<br />

edge entering v. For each edge e = (u, v), with cost c e >_ O, we define its modified<br />

cost c’ e to be ce - Yv- Note that since ce >_ y,, all the modified costs are still<br />

nonnegafive. More crucially, our discussion motivates the following fact.<br />

(4.37) T is an optimal arborescence in G subject to costs (Ce) if and Only if it<br />

is an optimal arborescence Subject to the modified costs c’<br />

ProoL Consider an arbitrary arborescence T. The difference between its cost<br />

with costs (ce} and [c’ e} is exactly ~,#r y~--that is,<br />

eaT<br />

eaT \<br />

4.9 Minimum-Cost Arborescences: A Multi-Phase Greedy <strong>Algorithm</strong><br />

This is because an arborescence has exactly one edge entering each node<br />

in the sum. Since the difference between the two costs is independent of the<br />

choice of the arborescence T, we see that T has minimum cost subiect to {ce}<br />

if and only if it has minimum cost subject to {c’e}. ,,<br />

We now consider the problem in terms of the costs {de}. All the edges in<br />

our set F* have cost 0 under these modified costs; and so if (V, F*) contains<br />

a cycle C, we know that all edges in C have cost 0. This suggests that we can<br />

afford to use as many edges from C as we want (consistent with producing an<br />

arborescence), since including edges from C doesn’t raise the cost.<br />

Thus our algorithm continues as follows. We contract C into a single<br />

supemode, obtaining a smaller graph G’ = (V’, E’). Here, V’ contains the nodes<br />

of V-C, plus a single node c* representing C. We transform each edge e E E to<br />

an edge e’ E E’ by replacing each end of e that belongs to C with the new node<br />

c*. This can result in G’ having parallel edges (i.e., edges with the same ends),<br />

which is fine; however, we delete self-loops from E’--edges that have both<br />

ends equal to c*. We recursively find an optimal arborescence in this smaller<br />

graph G’, subject to the costs {C’e}. The arborescence returned by this recursive<br />

call can be converted into an arborescence of G by including all but one edge<br />

on the cycle C.<br />

In summary, here is the full algorithm.<br />

For each node u7 &r<br />

Let Yu be the minimum cost of an edge entering node<br />

Modify the costs of all edges e entering v to c’e=c e<br />

Choose one 0-cost edge entering each u7~r, obtaining a set F*<br />

If F* forms an arborescence, then return it<br />

Else there is a directed cycle C_CF*<br />

Contract C to a single supernode, yielding a graph G’= (V’,E’)<br />

Recursively find an optimal arborescence (V’,F’) in G’<br />

with costs [C’e}<br />

Extend (V’,F ~) to an arborescence (V, F) in G<br />

by adding all but one edge of C<br />

~ Analyzing the <strong>Algorithm</strong><br />

It is easy to implement this algorithm so that it runs in polynomial time. But<br />

does it lead to an optimal arborescence? Before concluding that it does, we need<br />

to worry about the following point: not every arborescence in G corresponds to<br />

an arborescence in the contracted graph G’. Could we perhaps "miss" the true<br />

optimal arborescence in G by focusing on G’? What is true is the following.<br />

181

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!