3/29/05 Tucker, Sec. 4.2 1
Applied Combinatorics, 4th Ed.Alan Tucker
Section 4.2Minimal Spanning Trees
Prepared by Amanda Dargie and Michele Fretta
3/29/05 Tucker, Sec. 4.2 2
• Recall: A spanning tree of a graph G is a subgraph of G that is a tree containing all vertices of G.
3
2
6 9
151
11
3
2 74
3
6
2
2
Recall
3/29/05 Tucker, Sec. 4.2 3
Definition
• A minimal spanning tree in a network is a spanning tree whose sum of edge lengths k(e) is as small as possible.
12
3
2
6 9
151
3
2 74
3
6
2
2
3/29/05 Tucker, Sec. 4.2 4
Kruskal’s Algorithm
• Let T be a minimal spanning set (which is initially empty).
• Add to T the shortest edge that does not form a circuit with edges already in T.
• Repeat adding edges in this manner until set T has n-1 edges
3/29/05 Tucker, Sec. 4.2 5
Example• First include all 3 edges of length 1:
(a, f), (l, q), (r, w)
• Next add all the edges of length 2: (a, b), (e, j), (g, l), (h, i), (l, m), (p, u), (s, x), (x, y)
• Next add almost all the edges of length 3: (c, h), (d, e), (k, l), (k, p), (q, v), (r, s), (v, w), but not (w, x) unless (r, s) were omitted [if both were present we would get a circuit containing these 2 edges together with edges (r, w) and (s, x)
• Next add all the edges of length 4 (f, g), (h, m), (c, d), (n, o), (s, t)
• Finally add either (m, n) or (o, t) to obtain a minimal spanning set
f
o
p
tj
a
y
k
w
x
ql
n
m r
s
v
u
i
h
g
d
c
b
e
2
5
5
7
3
7
3
3287
43 5
2 9 5
4 2
6
8
1
10
3
1
3
4
2
7 3 2
4
6
24
8
2
1
5
3
X
3/29/05 Tucker, Sec. 4.2 6
Prim’s Algorithm
• Let T be a minimal spanning tree, initially including any one edge of shortest length.
• Add to T the shortest edge between a vertex in T and a vertex not in T.
• Repeat adding edges in this manner until T has n-1 edges.
3/29/05 Tucker, Sec. 4.2 7
Example
• There are 3 edges of length 1: (a, f), (l, q), (r, w)
• Suppose we pick (a, f)
• Next add (a, b), of length 2
• Then (f, g), of length 4
• Then (g, l), (l, q), (l, m) and so forth
• The next-to-last addition can be either (m, n), (o, t) (both of length 5) – in this case we’ll use (m, n)
• Then follow with (n, o)
a
y
k
w
x
ql
n
m r
s
v
u
i
h
g
d
c
b
e
2
5
5
7
3
7
3
3287
43 5
2 9 5
4 2
6
8
1
10
3
1
3
4
2
7 3 2
4
6
24
8
2
1
5
3
f
j
p
o t
3/29/05 Tucker, Sec. 4.2 8
Theorem• Prim’s algorithm yields a minimal spanning tree.
Proof• Assume that all edges have different lengths.
• Let T ' be a minimal spanning tree chosen to have as many edges as possible in common with T* (which will be constructed by Prim’s algorithm).
3/29/05 Tucker, Sec. 4.2 9
Proof (cont’d)
1
If * ', then the theorem is true.
If * ', let ( , ) be the first edge which
is chosen by Prim's algorithm that is NOT in '.
This means that the subtree (composed of the
first 1 edges
k
k
T T
T T e a b
T
T
k
chosen by Prim's algorithm, is part
of the minimal tree '.T
3/29/05 Tucker, Sec. 4.2 10
Proof (cont’d)
1
In this diagram of ',
edges of are red,
edge is dotted,
and other edges are black.
k
k
T
T
e
a
b
ke
3/29/05 Tucker, Sec. 4.2 11
Proof (cont’d)
a
b
ke
*e
-1
Since is not in the minimal spanning tree ', there is a path (call it ) in
' that connects to .
At least one of the edges of must not be in , because otherwise
would form a circu
k
k k
e T P
T a b
P T P e
1
1
it in the tree (which is formed by the first edges
in Prim's algorithm).
Let * be the first edge along (starting from ) that is not in .
Note that one end vertex of * is in .
k
k
k
T k
e P a T
e T
3/29/05 Tucker, Sec. 4.2 12
Proof (cont’d)
a
b
ke
*e
If * is lesser than , then on the th iteration, Prim's algorithm would have
incorporated * rather than .
On the other hand, if * is greater than , we remove * from ' and replace
it wit
k
k
k
e e k
e e
e e e T
h . The new ' is still a spanning tree, but its length is lesser, and this
contradicts the minimality of the original '.ke T
T
3/29/05 Tucker, Sec. 4.2 13
For the class to try:The red numbers indicate the value of each edge.
Find a minimal spanning tree.a
7
55
4
3
3
2
8
g
fe
dc
b
5
Hint: use Kruskal’s Algorithm
3/29/05 Tucker, Sec. 4.2 14
Solution
a
5
First, add (c,f) to TThen, add (a,b) and (d,g)Then, add (a,e)Then add (e,f) and (f,g). Don’t add (b,e), because we can’t have a circuit!
7
55
4
3
3
2
8
g
f
e
d
c
b