Algorithms
Lecture 12: Minimum Spanning Trees
We must all hang together, gentlemen, or else we shall most assuredly
hang separately.
— Benjamin Franklin, at the signing of the
Declaration of Independence (July 4, 1776)
It is a very sad thing that nowadays there is so little useless information.
— Oscar Wilde
A ship in port is safe, but that is not what ships are for.
— Rear Admiral Grace Murray Hopper
12 Minimum Spanning Trees
12.1 Introduction
Suppose we are given a connected, undirected,
weighted
graph. This is a graph
G
= (
V
,
E
)
together with
a function
w
:
E
→
IR that assigns a
weight w
(
e
)
to each edge
e
. For this lecture, we’ll assume that the
weights are real numbers. Our task is to ﬁnd the
minimum spanning tree
of
G
, that is, the spanning
tree
T
minimizing the function
w
(
T
) =
X
e
∈
T
w
(
e
)
.
To keep things simple, I’ll assume that all the edge weights are distinct:
w
(
e
)
6
=
w
(
e
0
)
for any pair of
edges
e
and
e
0
. Distinct weights guarantee that the minimum spanning tree of the graph is unique.
Without this condition, there may be several different minimum spanning trees. For example, if all the
edges have weight 1, then
every
spanning tree is a minimum spanning tree with weight
V

1.
8
5
10
2
3
18
16
12
14
30
4
26
A weighted graph and its minimum spanning tree.
If we have an algorithm that assumes the edge weights are unique, we can still use it on graphs
where multiple edges have the same weight, as long as we have a consistent method for breaking ties.
One way to break ties consistently is to use the following algorithm in place of a simple comparison.
S
HORTER
E
DGE
takes as input four integers
i
,
j
,
k
,
l
, and decides which of the two edges
(
i
,
j
)
and
(
k
,
l
)
has ‘smaller’ weight.
S
HORTER
E
DGE
(
i
,
j
,
k
,
l
)
if
w
(
i
,
j
)
<
w
(
k
,
l
)
return
(
i
,
j
)
if
w
(
i
,
j
)
>
w
(
k
,
l
)
return
(
k
,
l
)
if min
(
i
,
j
)
<
min
(
k
,
l
)
return
(
i
,
j
)
if min
(
i
,
j
)
>
min
(
k
,
l
)
return
(
k
,
l
)
if max
(
i
,
j
)
<
max
(
k
,
l
)
return
(
i
,
j
)
⟨⟨
if max(i,j)
<
max(k,l)
⟩⟩
return
(
k
,
l
)
1