18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Prim's <strong>Algorithm</strong><br />

Next: Kruskal's <strong>Algorithm</strong> Up: Minimum Spanning Trees Previous: Minimum Spanning Trees<br />

Prim's <strong>Algorithm</strong><br />

Every vertex will appear in the minimum spanning tree of any connected graph G. Prim's minimum spanning tree algorithm<br />

starts from one vertex and grows the rest of the tree one edge at a time.<br />

In greedy algorithms, we make the decision of what to do next by selecting the best local option from all available choices<br />

without regard to the global structure. Since we seek the tree of minimum weight, the natural greedy algorithm for minimum<br />

spanning tree repeatedly selects the smallest weight edge that will enlarge the tree.<br />

Figure: Where Prim's algorithm goes bad? No, because<br />

Prim-MST(G)<br />

non-tree vertex<br />

Select an arbitrary vertex to start the tree from.<br />

While (there are still non-tree vertices)<br />

Select the edge of minimum weight between a tree and<br />

Add the selected edge and vertex to the tree .<br />

Prim's algorithm clearly creates a spanning tree, because no cycle can be introduced by adding edges between tree and non-tree<br />

vertices. However, why should it be of minimum weight over all spanning trees? We have seen ample evidence of other<br />

natural greedy heuristics that do not yield a global optimium. <strong>The</strong>refore, we must be particularly careful to demonstrate any<br />

such claim.<br />

Suppose that there existed a graph G for which Prim's algorithm did not return a minimum spanning tree. Since we are<br />

building the tree incrementally, this means that there must have been some particular instant where we went wrong. Before we<br />

file:///E|/BOOK/BOOK2/NODE74.HTM (1 of 2) [19/1/2003 1:29:14]

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

Saved successfully!

Ooh no, something went wrong!