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

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

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

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

a tree of weight at most . <strong>The</strong>refore, we could not have made a mistake in selecting (x,y), and the correctness follows.<br />

What is the time complexity of Kruskal's algorithm? Inserting and retrieving m edges from a priority queue such as a heap<br />

takes time. <strong>The</strong> while loop makes at most m iterations, each testing the connectivity of two trees plus an edge. In<br />

the most simple-minded approach, this can be implemented by a breadth-first or depth-first search in a graph with at most n<br />

edges and n vertices, thus yielding an O(mn) algorithm.<br />

However, a faster implementation would result if we could implement the component test in faster than O(n) time. In fact, the<br />

union-find data structure, discussed in Section , can support such queries in time. With this data structure,<br />

Kruskal's algorithm runs in time, which is faster than Prim's for sparse graphs. Observe again the impact that the<br />

right data structure can have in implementing a straightforward algorithm.<br />

Next: Shortest Paths Up: Minimum Spanning Trees Previous: Prim's <strong>Algorithm</strong><br />

<strong>Algorithm</strong>s<br />

Mon Jun 2 23:33:50 EDT 1997<br />

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

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

Saved successfully!

Ooh no, something went wrong!