Algorithms
Lecture 18: Minimum Spanning Trees
[
Sp’10
]
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
18
Minimum Spanning Trees
18.1
Introduction
Suppose we are given a connected, undirected,
weighted
graph. This is a graph
G
= (
V
,
E
)
together with
a function
w
:
E
→
R
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 find 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.
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
)
18.2
The Only Minimum Spanning Tree Algorithm
There are several different methods for computing minimum spanning trees, but really they are all
instances of the following generic algorithm. The situation is similar to the previous lecture, where we
saw that depthfirst search and breadthfirst search were both instances of a single generic traversal
algorithm.
The generic minimum spanning tree algorithm maintains an acyclic subgraph
F
of the input graph
G
,
which we will call an
intermediate spanning forest
.
F
is a subgraph of the minimum spanning tree of
G
,
and every component of
F
is a minimum spanning tree of its vertices. Initially,
F
consists of
n
onenode
trees. The generic algorithm merges trees together by adding certain edges between them. When the
c
Copyright 2011 Jeff Erickson.
Released under a Creative Commons AttributionNonCommercialShareAlike 3.0 License (
http://creativecommons.org/licenses/byncsa/3.0/
).