28.11.2014 Views

Lecture Notes Discrete Optimization - Applied Mathematics

Lecture Notes Discrete Optimization - Applied Mathematics

Lecture Notes Discrete Optimization - Applied Mathematics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.4 Prim’s Algorithm<br />

Prim’s algorithm grows a single blue tree, starting at an arbitrary node s ∈ V. In every<br />

step, it chooses among all edges that are incident to the current blue tree T containing s an<br />

uncolored edge e i of minimum cost and colors it blue. The algorithm stops if T contains<br />

all nodes. We implicitly assume that all edges that are not part of the final tree are colored<br />

red in a post-processing step. The algorithm is summarized in Algorithm 2.<br />

Input: undirected graph G=(V,E) with edge costs c : E →R<br />

Output: minimum spanning tree T<br />

1 Initialize: all edges are uncolored<br />

(Remark: we implicitly maintain a forest of blue trees below)<br />

2 Choose an arbitrary node s<br />

3 for i←1to n−1 do<br />

4 Let T be the current blue tree containing s<br />

5 Select a minimum cost edge e i ∈ δ(V(T)) incident to T and color it blue<br />

6 end<br />

7 Implicitly: color all remaining edges red<br />

8 Output the resulting tree T of blue edges<br />

Algorithm 2: Prim’s MST algorithm.<br />

Note that the pre-conditions are met whenever the algorithm applies one of the two coloring<br />

rules: If the blue rule applies, then the node set V(T) of the current blue tree T<br />

containing s induces a cut (X, ¯X) with X = V(T). No blue edge crosses (X, ¯X) by construction.<br />

Moreover, e i is among all uncolored edges crossing the cut one of minimum<br />

cost and can thus be colored blue. If the red rule applies to edge e=(u,v), both endpoints<br />

u and v are contained in the final tree T . The path P uv in T together with e induce a cycle<br />

C. All edges in C∩ P uv are blue and we can thus color e red.<br />

The time complexity of the algorithm depends on how efficiently we are able to identify<br />

a minimum cost edge e i that is incident to T . To this aim, good implementations use a<br />

priority queue data structure. The idea is to keep track of the minimum cost connections<br />

between nodes that are outside of T to nodes in T . Suppose we maintain two data entries<br />

for every node v /∈ V(T): π(v) = (u,v) refers to the edge that minimizes c(u,v) among<br />

all u∈ V(T) and d(v)=c(π(v)) refers to the cost of this edge; we define π(v)=nil and<br />

d(v)=∞ if no such edge exists. Initially, we have for every node v∈ V \{s}:<br />

π(v)=<br />

nil<br />

{<br />

(s,v) if (s,v)∈E<br />

otherwise.<br />

and<br />

d(v)=<br />

∞<br />

{<br />

c(s,v) if(s,v)∈E<br />

otherwise.<br />

The algorithm now repeatedly chooses a node v /∈ V(T) with d(v) minimum, adds it to<br />

the tree and colors its connecting edge π(v) blue. Because v is part of the new tree,<br />

we need to update the above data. This can be accomplished by iterating over all edges<br />

(v,w) ∈ E incident to v and verifying for every adjacent node w with w /∈ V(T) whether<br />

the connection cost from w to T via edge (v,w) is less than the one stored in d(w) (via<br />

π(w)). If so, we update the respective data entries accordingly. Note that if the value of<br />

12

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

Saved successfully!

Ooh no, something went wrong!