Professional Documents
Culture Documents
Lecture 8: Kruskal's MST Algorithm: CLRS Chapter 23
Lecture 8: Kruskal's MST Algorithm: CLRS Chapter 23
CLRS Chapter 23
Main Topics of This Lecture
Kruskals algorithm
Another, but different, greedy MST algorithm
Outline by Example
10
5
3
e
12
c
2
c
e
forest
original graph
edge
{d, c}
{a, e}
{a, d}
{e, d}
{b, c}
{a, b}
{b, d}
weight
2
3
5
7
9
10
12
d
MST
Forest (V, A)
A={
Step 0: Set
and
to
Step 2: If
, stop and output the minimal span
ning tree
. Otherwise go to Step 1.
is a
with min-
with mini-
in order of in-
If
Union( ):
Merge the sets respectively containing
into a common set.
and
/* After sorting
!#"
;
for (each
in ) CREATE-SET( );
for %$
do
&$ '$ from 1 to
if (FIND-SET( $ ) != FIND-SET( $ ) )
(
add $ $ to ;
UNION( $ $ );
return(A);
Remark: With a proper implementation of UNION-FIND, Kruskals
algorithm has running time
*,+.-/0-21!3546-!0- 7
*/
crosses this
3. Since adding to
does not induce a cy
cle, crosses the cut. Moreover, since
is currently the smallest edge, is the light
edge crossing the cut. This completes the correctness proof of Kruskals Algorithm.
10
G=(V, E)
11