COMPUTING THE M I N I M U M SPANNING TREE

10.6 COMPUTING THE M I N I M U M SPANNING TREE

A tree is a connected (undirected) graph with no cycles. Given an undirected and connected graph G =

G such that

E), a spanning tree of G is a

G' = (V', E') of

(i) G' is a tree, and (ii) V' =

G is weighted, then a minimum spanning tree (MST) of G has the smallest edge-weight sum among all spanning trees of

If the graph

G. These definitions are illustrated in Fig. 10.8. Three spanning trees of the weighted graph in Fig.

are shown in Figs.

Figure 10.8 Weighted graph and three of its spanning trees.

262 Graph Theory Chap. 10 The tree in Fig.

has minimum weight. Note that when all the edges of the graph have distinct weights, the MST is unique. If V =

then the MST has n - 1 edges. These edges must be chosen among potentially n(n -

v,, . .. ,

candidates. This gives an lower bound on the number of operations required to compute the MST since each edge must be examined at least once. For convenience, we henceforth refer to the weight of edge

as the distance separating and and denote it by

A sequential algorithm for computing the MST based on the greedy approach to problem solving proceeds in stages. Beginning with an arbitrarily chosen vertex, each stage adds one vertex and an associated edge to the tree. If is a vertex that is not yet in the tree, let

denote a vertex already in the tree that is closest to The algorithm therefore consists of two steps:

Step 1: Include vertex

in the MST and let

for i =

1, 2,. . . , n - 1.

Step

2: This step is repeated as long as there are vertices not yet in the MST: (2.1) Include in the tree the closest vertex not yet in the tree; that is, for all

not in the MST find the edge for which is smallest and add it to the tree.

(2.2) For all not in the MST, update that is, assuming that was the most recently added vertex to the tree, then

can be updated by determining the smaller of

and

Step 1 requires n constant time operations. Step 2 is executed once for each of n - 1 vertices. there are already k vertices in the tree, then steps 2.1 and 2.2 consist of n - k - 1 and n - k comparisons, respectively. Thus step 2, and hence the algorithm, require time proportional to

(n - k), which is O(n Z ). This sequential running time is therefore optimal in view of the lower bound stated previously. We now show how this algorithm can be adapted to run in parallel on an EREW SM SIMD computer. The parallel implementation uses N processors

The number of processors is independent of the number of vertices in except that we assume 1 N n. As we did in earlier chapters, we find it convenient to write N =

is assigned a distinct subsequence

where

1. Each processor

of V of size n x . In other words, is "in charge" of the vertices in Note that

During the process of constructing the MST and for each vertex in

needs only to store the indices of the first and last vertices in

that is not yet in the tree,

also keeps track of the closest vertex in the tree, denoted The weight matrix W of G is stored in shared memory, where

for

i, j =

. . , n - 1. If i = j or if and are not directly connected by an edge, then

The algorithm initially includes an arbitrary vertex in the tree. The computation of the MST then proceeds in n - 1 stages. During each stage, a new vertex and hence a new edge are added to the existing partial tree. This is done as

follows. With all processors operating in parallel, each processor finds among its vertices not yet in the tree the vertex closest to (a vertex in) the tree. Among the

10.6 Computing the Minimum Spanning Tree 263 vertices thus found, the vertex closest to (a vertex in) the tree is found and added to the

tree along with the associated edge. This vertex, call it v,, is now made known to all processors. The following step is then performed in parallel by all processors, each for

its vertices: For each vertex not yet in the tree, if then is made equal to The algorithm is given in what follows as procedure EREW MST. The procedure uses procedures BROADCAST and MINIMUM described in sections

2.5.1 and 6.3.1, respectively. It produces an array TREE in shared memory containing the n - 1 edges of the MST. When two distances are equal, the procedure breaks the tie arbitrarily.

procedure EREW MST

TREE)

Step 1: (1.1) Vertex

in

is labeled as a vertex already in the tree

(1.2) for i = to N - 1 do in parallel

for each vertex

in

do

end for end for.

Step 2: for i = 1 to n - 1 do

(2.1) for j= to N - 1 do in parallel

(i) finds the smallest of the quantities where is a vertex in that is not yet in the tree (ii) Let the smallest quantity found in (i) be

v,): delivers a triple

(2.2) Using procedure MINIMUM the smallest of the distances

and its associated vertices

1, are found; let this triple be (d,, a,, b,), where a, is some vertex

not in the tree and b, is some vertex already in the tree (2.3)

the ith entry of array TREE (2.4) Using BROADCAST,

assigns

to

is made known to all N processors (2.5) for j = to N - 1 do in parallel (i) if

as a vertex already in the tree

end if

(ii) for each vertex

in

that is not yet in the tree do

if

then end if

end for end for end for.

264 Graph Theory Chap. 10 Analysis.

Step 1.1 is done in constant time. Since each processor is in charge of n x vertices, step 1.2 requires n x assignments. Therefore step 1 runs in O(n x ) time. In step

2.1, a processor finds the smallest of n x quantities (sequentially) using n x - 1 comparisons. Procedures MINIMUM and BROADCAST both involve

N) constant time operations. Since N =

steps 2.2 and 2.4 are done in n) time. Clearly steps 2.3 and 2.5 require constant time and O(n x ) time, respectively. Hence each iteration of step

2 takes O(n x ) time. Since this step is iterated n + 1 times, it is

completed time. Consequently, the overall running time of the procedure is The procedure is therefore adaptive. Its cost is

This means that the procedure is also cost optimal. Note that, for sufficiently large n,n X

n. The procedure's optimality is therefore limited to the range N

Let G be a weighted nine-node graph whose weight matrix is given in Fig. 10.9. Also assume that a n EREW SM SIMD computer with three processors is available. Thus

Figure 10.9 Weight matrix for example 10.4.

Figure 10.10 Computing minimum spanning tree using procedure EREW MST.

Graph Theory Chap. 10 3 =

that is,

= 0.5. Processors

and

are assigned sequences

v,). In step 1.1, is included in the tree and is assigned as the closest vertex in the tree to all remaining vertices. During the first iteration of step 2,

and

and returns the triple (5,

determines that

and (5, v,, respectively. Procedure MINIMUM is then used to determine

and hence

Now is made known to all processors using BROADCAST and labels it as a vertex in the tree. In step 2.5,

equal to P, updates to

keeps

and

but keeps

and

keeps

and = while updating

The process continues until the tree generated. This is illustrated in Fig. 10.10.