



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































Importance of Minimal Spanning Trees (MST)
-^
MST Problem– Definitions and analysis– Generic Solution– Proofs of correctness
-^
Kruskal’s Algorithm– Algorithm– Analysis
-^
Prim’s Algorithm– Algorithm– Analysis
-^
Conclusion
Minimum spanning trees are not unique–^
If we replace (b, c) with (a, h), get a different spanningtree with the same cost
-^
MST have no cycles–^
We can take out an edge of
-^
a cycle, and still have the
-^
vertices connected while reducing the cost
4 8
11
8
2
7
1
2
6
(^74)
14
(^910)
a
b
g
h
i
c
d f
e
Minimum-spanning-tree problem
: Find a MST for a
connected, undirected graph, with a weight functionassociated with its edges A generic solution: •^
Build a set A of edges(initially empty)
-^
Incrementally add edges to Asuch that they would belong to a MST
-^
An edge
(u, v)
is
safe
for A
A
{(u, v)
}
is also a subset of some MST
4 8
11
8
2
7
1
2
6
(^74)
14
(^910)
a
b
g
h
i
c
d f
e
,^ w
while
does not form a spanning tree
do
find an edge
( u
,^ v
) that is safe for
u ,
v
return
InitializationTermination
Maintenance
The algorithm uses greedy strategy which growsMST one edge at a time.
-^
Given a connected, undirected graph
= (V, E) with
a weight function
w :
Algorithm manages a set of edges
, maintaining
loop invariant^ Prior to each iteration, A is a subset of some MST
-^
An edge
(u, v)
is a
safe edge
for
such that
u, v
)} is also a subset of some MST.
Algorithms, discussed here, to find safe edge are
Let
) be a connected, undirected graph
with a real-valued weight function
w
on
. Let
be
a subset of
that is included in some minimum
spanning tree for
, let (
) be any cut of
that respects
, and let (
u ,
v
) be a light edge
crossing (
). Then, edge (
u ,
v
) is safe for
Proof•^
Let
be a minimum spanning
tree that includes
A (edges
of A are shaded)
Assume that
does not
contain the light edge (
u ,
v
since if it does, we are done.
y
u
x
v
S
V - S
Construction of another MST,•^
For (u, v)
-^
We construct another MST T
′^ that includes A
{(u, v)}
by cut-and-paste, and showing that (u, v) is a safe A.
-^
Since (u, v) crosses cut set (S, V-S) and
-^
(u, v)
T,
-^
Hence there must be an edge (x, y)
T which crosses
the cut set
-^
By removing (x, y) breaks T into two components.
-^
Adding (u, v) reconnects them to form a new spanningtree T
′^ = T - {(x, y)}
{(u, v)}.
,^ w
for
each vertex
v
do
( v
4 sort edges in non-decreasing order by weight
w
5 for
each
( u
,^ v
) in non-decreasing order by weight
do if
( u
v )
then
u ,
v
u ,
v
9 return
Total Running time = O (E lg V),
2 6
10
2
7
4
8
7
(^118)
1
4
14
9
a
b
g
h
i
c
d f
e
Initial sets =
{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}
Edges
Weight
(g, h)
1
(c, i)
2
(f, g)
2
(a, b)
4
(c, f)
4
(g, i)
6
(c, d)
7
(h, i)
7
(a, h)
8
(b, c)
8
(d, e)
9
(e, f)
10
(b h)
11
(d, f)
14
2 6
10
2
7
4
8
7
(^118)
1
4
14
9
a
b
g
h
i
c
d f
e
(c, i)
is the least weight edge FIND-SET
(c)
≠
FIND-SET
(i)
A
A
{(c, i)}
UNION
(c, i)
Initial sets =
{a}, {b}, {
c }, {d}, {e}, {f}, {g, h}, {
i }
Final sets =
{a}, {b}, {
c, i
}, {d}, {e}, {f}, {g, h}
2 6
10
2
7
4
8
7
(^118)
1
4
14
9
a
b
g
h
i
c
d f
e
(f, g)
is the least weight edge FIND-SET
(f)
≠
FIND-SET
(g)
A
A
{(f, g)}
UNION
(f, g)
Initial sets =
{a}, {b}, {c, i}, {d}, {e}, {
f }, {
g , h}
Final sets =
{a}, {b}, {c, i}, {d}, {e}, {
f, g, h
}
2 6
10
2
7
4
8
7
(^118)
1
4
14
9
a
b
g
h
i
c
d f
e
(c, f)
is the least weight edge FIND-SET
(c)
≠
FIND-SET
(f)
A
A
{(c, f)}
UNION
(c, f)
Initial sets =
{a, b}, {
c , i}, {d}, {e}, {
f , g, h}
Final sets
= {a, b}, {
c, f, g, h
,^ i }, {d}, {e}
2 6
10
2
7
4
8
7
(^118)
1
4
14
9
a
b
g
h
i
c
d f
e
(g, i)
is the least weight edge FIND-SET
(g) =
FIND-SET
(i)
Initial sets =
{a, b}, {c, f,
g,
h ,^ i }, {d}, {e}
Final sets =
{a, b}, {c, f, g, h
,^ i}, {d}, {e}