• No results found

Jarn´ık’s algorithm and Bor˚ uvka’s algorithm

In document Invitation to Discrete Mathematics (Page 194-200)

Graphs: an introduction

5.5 Jarn´ık’s algorithm and Bor˚ uvka’s algorithm

What we call “Jarn´ık’s algorithm” is mostly known under the name

“Prim’s algorithm”. However, since Prim’s paper is dated 1957 while

5.5 Jarn´ık’s algorithm and Bor˚uvka’s algorithm 177 Jarn´ık4already described the same algorithm in an elegant and precise way in 1930 (continuing the work of Bor˚uvka who published the first documented algorithm for the minimum spanning tree problem in 1928), we believe it is appropriate to use the name of the first inventor.

Nowadays, Jarn´ık’s algorithm can be viewed as a simple extension of Algorithm 5.3.5.

5.5.1 Algorithm. [Jarn´ık’s algorithm] Proceed according to Alg-orithm 5.3.5, and always choose the newly added edge ei as an edge of the smallest possible weight from the set {{x, y} ∈ E(G): x ∈ Vi−1, y∈ Vi−1}.

5.5.2 Proposition (Correctness of Jarn´ık’s algorithm).

Jarn´ık’s algorithm finds a minimum spanning tree for every connected network.

Proof. Let T = (V, E) be the spanning tree resulting from Jarn´ık’s algorithm, and suppose that the edges of E are numbered e1through en−1 in the order they were added to T . For contradiction, suppose that T is not a minimum spanning tree.

Let T be some minimum spanning tree. Let k(T) denote the index k for which all the edges e1, e2, . . . , ek belong to E(T) but ek+1∈ E(T). Among all minimum spanning trees, select one which has the maximum possible value of k and denote it by ˇT = (V, ˇE).

Write k = k( ˇT ).

Now consider the moment in the algorithm’s execution when the edge ek+1has been added to T . Let Tk= (Vk, Ek) be the tree formed by the edges e1, . . . , ek. Then ek+1 has the form {x, y}, where x ∈ V (Tk) and y ∈ V (Tk). Consider the graph ˇT + ek+1. This graph contains some cycle C (since it is connected and has more than n−1 edges), and such a C necessarily contains the edge ek+1 (see also Exercise 5.4.2).

The cycle C consists of the edge ek+1 = {x, y} plus a path P connecting the vertices x and y in the spanning tree ˇT . At least one edge of the path P has one vertex in the set Vkand the other vertex outside Vk. Let e be some such edge. Obviously e= ek+1, and further we know that e ∈ ˇE and ek+1 ∈ ˇE; see Fig. 5.1. Both the edges e and ek+1 connect a vertex of Vk with a vertex not lying in Vk, and by the edge selection rule in the algorithm we get w(ek+1)≤ w(e).

4An approximate pronunciation is YAR-neekh, and for Bor˚uvka it is BOH-roof-kah.

ek+1

x

y Vk

e

P Tˇ

Fig. 5.1 Illustration for the correctness proof of Jarn´ık’s algorithm.

Now consider the graph T = ( ˇT + ek+1)−e. This graph has n−1 edges and, as is easy to check, it is connected; hence it is a spanning tree. We have w(E(T)) = w( ˇE)− w(e) + w(ek+1)≤ w( ˇE), and thus T is a minimum spanning tree as well, but with k(T) > k( ˇT ). This contradiction to the choice of ˇT proves Proposition 5.5.2.

Warning. This is another proof of a slippery nature: make one step slightly differently and the whole thing falls apart. 2 Bor˚uvka’s algorithm. In conclusion, let us mention the historically first algorithm for minimum spanning tree computation due to Bor˚uvka.

As is usual in science, the first method discovered was not the simplest—

both Kruskal’s and (in particular) Jarn´ık’s algorithm are conceptually simpler. But yet it was Bor˚uvka’s algorithm that recently became a starting point for the theoretically fastest known algorithm for the min-imum spanning tree problem (Karger, Klein, and Tarjan [40]). This lat-ter algorithm is fairly complicated and uses a number of other ideas (which we will not pursue here) to make the computation fast.

5.5.3 Algorithm (Bor˚uvka’s algorithm). The input is a graph G = (V, E) with edge weight function w. We need to assume, moreover, that distinct edges get distinct weights, i.e. that the weight function is one-to-one. This assumption is not particularly restrictive. Each weight function can be converted into a one-to-one function by arbitrarily small changes of the weights, which changes the weight of a minimum span-ning tree by an arbitrarily small amount. (Alternatively, the algorithm can be modified to work with arbitrary weight functions, by adding a simple tie-breaking rule outlined in Exercise 6 below.)

The algorithm successively constructs sets E0, E1, . . .⊆ E of edges, beginning with E0=∅.

Suppose that the set Ei−1 has already been computed, and let (V1, . . . , Vt) be the partition of the vertex set according to the

5.5 Jarn´ık’s algorithm and Bor˚uvka’s algorithm 179 components of the graph (V, Ei−1). Strictly speaking, this partition should also have the index i since it is different in each step, but we omit this index in order to make the notation simpler. For each set Vj of this partition we find the edge ej = {xj, yj} (where xj ∈ Vj, yj∈ Vj) whose weight is minimum among all edges of the form{x, y}, x∈ Vj, y ∈ V \ Vj (it may happen that ej = ej for j = j). We put Ei= Ei−1∪ {e1, . . . , et}. The algorithm finishes when the graph (V, Ei) has a single component.

The algorithm could also be called a “bubbles algorithm”. The graph G is covered by a collection of “bubbles”. In each step, we merge each bubble with its nearest neighboring bubble.

We will not prove the correctness of this algorithm. We only show that the constructed graph has no cycle (which, unlike the previous algorithms, is not quite obvious). So suppose for contradiction that a cycle arose in some step i. This means that there are pairwise distinct indices j(1), j(2), . . . , j(k) for which

xj(1)∈ Vj(1), yj(1)∈ Vj(2)

xj(2)∈ Vj(2), yj(2)∈ Vj(3)

...

xj(k−1)∈ Vj(k−1), yj(k−1)∈ Vj(k)

xj(k)∈ Vj(k), yj(k)∈ Vj(1). Here is an illustration:

Vj(k)

Vj(1) Vj(2)

Vj(3) xj(1) yj(1)

xj(2)

yj(2), xj(3)

yj(k) xj(k)

yj(k−1)

Since distinct edges have distinct weights, the edge ej()always has the smallest weight among the edges leaving the component Vj(), and in particular, we get

w(ej(1)) < w(ej(2)) <· · · < w(ej(k)) < w(ej(1)).

This chain of strict inequalities cannot hold and so Bor˚uvka’s algorithm finds some spanning tree of G. With some more effort, it can be proved

that it finds the minimum spanning tree. 2

Example. Consider the following network (the weights are given as labels of the edges):

12 9

8 2 16

1 15

11 7

14

13 5

17 3

4 10 6

Jarn´ık’s algorithm started in the upper left corner proceeds as follows:

Kruskal’s algorithm needs 17 steps (but only in 10 of them is a new edge added). Bor˚uvka’s algorithm, on the other hand, is quite short:

But in each step we have to do much more work.

Exercises

1. (General spanning tree algorithm) Consider the following algorithm for the minimum spanning tree problem. The input is a connected graph G = (V, E) with weight function w. We put E0 = ∅. Suppose that Ei−1 has already been defined. Choose an arbitrary component Vi of the graph (V, Ei−1), select an edge ei of the minimum weight among the edges with one vertex in Vi and the other vertex not in Vi, and set Ei = Ei−1∪ {ei}. Prove that (V, En−1) is a minimum spanning tree.

(Imitate the correctness proof for Jarn´ık’s algorithm.)

Check that this proves the correctness of both Kruskal’s and Jarn´ık’s algorithm.

2. (“Inverse” greedy algorithm) Consider the following algorithm for the minimum spanning tree problem. The input is a connected graph G = (V, E) with weight function w. Label the edges e1, . . . , em in such a way that w(e1)≥ · · · ≥ w(em). Put E0= E, and

Ei=

Ei−1\ {ei} if the graph (V, Ei−1\ {ei}) is connected

Ei otherwise.

Prove that (V, Em) is a minimum spanning tree of G.

5.5 Jarn´ık’s algorithm and Bor˚uvka’s algorithm 181 3. Prove the correctness of Bor˚uvka’s algorithm.

4. CS Design the details of Jarn´ık’s algorithm in such a way that its time complexity is O((m + n) log n) (this probably requires some basic knowledge of data structures).

5. (a) Prove that Bor˚uvka’s algorithm has at most O(log n) phases, i.e.

the graph (V, Ei) is connected already for some i = O(log n).

(b) CS Design the details of Bor˚uvka’s algorithm in such a way that its time complexity is at most O((m + n) log n).

6. (Tie-breaking in Bor˚uvka’s algorithm) Given an arbitrary weight func-tion on edges of a graph G = (V, E), we choose an arbitrary ordering e1, e2, . . . , em of the edges once and for all, and we define ei ej if either w(ei) < w(ej) or both w(ei) = w(ej) and i≤ j.

(a) Formulate Bor˚uvka’s algorithm with edges ordered by the linear ordering (instead of the usual ordering ≤ on the weights).

(b) Check that the algorithm in (a) computes a spanning tree of G.

(c) Prove that the algorithm in (a) computes a minimum spanning tree of G with respect to the weight function w (modify the proof in Exercise 3).

In document Invitation to Discrete Mathematics (Page 194-200)