11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

398 Chap. 11 GraphsInitialA B C D E FStep 1 A BProcess edge (C, D)1CDEFStep 2AProcess edge (E, F)B1CDE1FStep 3AProcess edge (C, F)BC1 2DFE 1Figure 11.24 Illustr<strong>at</strong>ion of the first three steps of Kruskal’s MST algorithm asapplied to the graph of Figure 11.20.The only tricky part to this algorithm is determining if two vertices belong tothe same equivalence class. Fortun<strong>at</strong>ely, the ideal algorithm is available for thepurpose — the UNION/FIND algorithm based on the parent pointer represent<strong>at</strong>ionfor trees described in Section 6.2. Figure 11.25 shows an implement<strong>at</strong>ion for thealgorithm. Class KruskalElem is used to store the edges on the min-heap.Kruskal’s algorithm is domin<strong>at</strong>ed by the time required to process the edges.The differ <strong>and</strong> UNION functions are nearly constant in time if p<strong>at</strong>h compression<strong>and</strong> weighted union is used. Thus, the total cost of the algorithm is Θ(|E| log |E|)in the worst case, when nearly all edges must be processed before all the edges ofthe spanning tree are found <strong>and</strong> the algorithm can stop. More often the edges of thespanning tree are the shorter ones,<strong>and</strong> only about |V| edges must be processed. Ifso, the cost is often close to Θ(|V| log |E|) in the average case.

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

Saved successfully!

Ooh no, something went wrong!