12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

416 Chap. 11 GraphsMarkedVertices v i , i < jv u“correct” edgee ′UnmarkedVertices v i , i ≥ jv wv pe jPrim’s edgeFigure 11.22 Prim’s MST algorithm proof. The left oval contains that portion ofthe graph where Prim’s MST <strong>and</strong> the “true” MST T agree. The right oval containsthe rest of the graph. The two portions of the graph are connected by (at least)edges e j (selected by Prim’s algorithm <strong>to</strong> be in the MST) <strong>and</strong> e ′ (the “correct”edge <strong>to</strong> be placed in the MST). Note that the path from v w <strong>to</strong> v j cannot includeany marked vertex v i , i ≤ j, because <strong>to</strong> do so would form a cycle.(C, B), (C, D), <strong>and</strong> (C, F). From these choices, the least-cost edge from theMST is (C, D). So we add Vertex D <strong>to</strong> the MST. For the next iteration, ouredge choices are (A, E), (C, B), (C, F), <strong>and</strong> (D, F). Because edges (C, F)<strong>and</strong> (D, F) happen <strong>to</strong> have equal cost, it is an arbitrary decision as <strong>to</strong> whichgets selected. Let’s pick (C, F). The next step marks Vertex E <strong>and</strong> addsedge (F, E) <strong>to</strong> the MST. Following in this manner, Vertex B (through edge(C, B)) is marked. At this point, the algorithm terminates.v j11.5.2 Kruskal’s <strong>Algorithm</strong>Our next MST algorithm is commonly referred <strong>to</strong> as Kruskal’s algorithm. Kruskal’salgorithm is also a simple, greedy algorithm. We first partition the set of verticesin<strong>to</strong> |V| equivalence classes (see Section 6.2), each consisting of one vertex. Wethen process the edges in order of weight. An edge is added <strong>to</strong> the MST, <strong>and</strong> thetwo equivalence classes combined, if the edge connects two vertices in differentequivalence classes. This process is repeated until only one equivalence class remains.

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

Saved successfully!

Ooh no, something went wrong!