
9.6 MINIMAL SPANNING TREE 285
the labels for the connecting nodes of this arc to be u
3
= u
4
= 2 because the nodes do
not intersect any of the other labeled nodes. Continuing, on iteration 3, we pick the next
shortest distance arc (4, 5), which does not create a cycle with the previously chosen arcs.
Now, 4 belongs to a different set of previously labeled nodes than does 5. Hence, we set
the labels of the two sets to be equal; we arbitrarily set the labels to be 1 for nodes 2, 3,
4, and 5. We continue in this manner, picking arc (1, 2) on iteration 4 and arc (4, 6) on
the final iteration.
Algorithm 9.4 (Minimal Spanning Tree) The algorithm starts by reindexing the
arcs α =1,...,m so that they are in the order of nondecreasing arc lengths. The nodes
will be partitioned into several membership classes, with each node assigned a unique
positive membership label u
j
> 0; upon termination all nodes will belong to only one
membership class. Initially all u
j
= 0, meaning that they do not belong yet to any
membership class. Let T be the set of arcs in the minimal spanning tree, let ν represent
the number of arcs assigned so far to the minimal spanning tree, let k represent the last
membership class label assigned to a node, and let α be the iteration counter, which is,
in this case, the index of the arc being considered for candidacy in the minimal spanning
tree.
1. Set T ← {∅}, ν ← 0, k ← 0, and α ← 1.
2. If ν = m − 1, terminate; we have found a minimal spanning tree.
3. Let arc α connect nodes i and j. We use the node labels to determine whether
candidate arc α forms a cycle with the arcs in T . If it forms a cycle, it is rejected;
otherwise it is accepted as belonging to the minimal spanning tree.
(a) Reject arc α if it will create a cycle with the arcs in T .Ifu
i
= u
j
= 0, i.e.,
nodes i and j both belong to the same membership class, then arc α will create
a cycle amongst arcs already selected as belonging to the minimal spanning
tree, and therefore arc α is rejected. Go to Step 4.
(b) Accept arc α if it does not create a cycle with the arcs in T . In this case set
T←T∪{α}, ν ← ν + 1, and update the labels of the membership classes by
doing one of the following:
• If u
i
= u
j
= 0, i.e., nodes i and j do not belong to any membership class,
then set k ← k + 1 followed by setting u
i
← k and u
j
← k.
• If 0 = u
i
= u
j
= 0 then the nodes i and j belong to different membership
classes. We merge the two membership classes labeled u
i
and u
j
into one.
That is, we change the labels of all nodes p such that u
p
= u
j
to u
p
← u
i
.
• If u
i
= 0, but u
j
= 0 set u
j
← u
i
.
• If u
j
= 0, but u
i
= 0 set u
i
← u
j
.
4. Set α ← α + 1. Go to Step 2.
LEMMA 9.16 (Spanning Tree in a Connected Network) A connected
network contains a spanning tree.
Exercise 9.28 Prove Lemma 9.16.