Math 275 – Graph Theory – Fall 2014 Solutions to practice problems X3. For the graph shown below, find a minimum weight spanning tree by using (i) Kruskal’s algorithm, and (ii) the Jarnı́k-Prim algorithm, starting at a. In each case show the edges of the tree on the graph, and provide a list of the edges of the tree in the order in which you added them to the tree. m 1 ℓ 13 4 21 5 n j 3 i 10 25 h 18 13 g k 15 10 f 21 19 d 7 e 6 18 9 c 17 b 15 11 a Note: The class web site contains a file that you can use to print out copies of the graph. Solution. [4+4=8] (i) See at left below; the order of edges chosen is indicated by w(i) where i is the time chosen. Edges were considered in order of increasing weight; crossed out edges would have formed a cycle: ℓm : 1, jn : 3, ℓn : 4, jm : 5, be : 6, de : 7, bd : 9, f k : 10, ih : 10, ab : 11, gh : 13, jℓ : 13, ac : 15, f g : 15, bc : 17, ec : 18, f j : 18, df : 19 and stop because we now have a spanning tree; no need to consider more edges. So edges in order chosen are: ℓm, jn, ℓn, be, de, f k, ih, ab, gh, ac, f g, f j, df . m 1(1) ℓ 4(3) 13 21 5 n j 3(2) i 10(7) i 10(9) 25 h g 15(11) 19(13) d g 10(6) 21 7(5) 9 d 18 k f b 10(6) 21 7(3) e 6(2) 18 9 c 17 15(7) 19(5) e 6(4) 18(10) 13(8) k f 25 h 18(12) 13(9) m1(13) ℓ 4(12) 13 21 5 n j 3(11) c 17 b 15(10) 11(8) 15(4) 11(1) a a 1 (ii) See at right above; the order of edges chosen is indicated by w/i where i is the time chosen. Here are the edges considered at each time step; the chosen one is underlined. 1: ab, ac 5: df , ef 9: f j, hi, kj 13: jm, ℓm 2: ac, bc, bd, be 6: f g, f j, f k 10: f j, ij, kj 3: ac, bc, bd, ce, de, ef 7: f g, f j, kj 11: jℓ, jm, jn 4: ac, bc, ce, df, ef 8: f j, gh, kj 12: jℓ, jm, ℓn So edges in order chosen are: ab, be, de, ac, df , f k, f g, gh, hi, f j, jn, ℓn, ℓm. X6. Apply Dijkstra’s Algorithm to the weighted digraph shown below to find shortest paths from a to every other vertex. At each step draw a separate copy of the graph, showing the current outbranching, with permanent arcs solid and tentative arcs dashed, and with the value of ℓ(v) shown next to each vertex v. Note: the class web site contains a PDF file with a page containing multiple copies of this digraph, which you may use for your answer. 2 b d 27 a 17 5 14 8 f 3 7 13 12 c 11 e 4 Solution. [8] We show vertices as v/ℓ where v is the vertex name and ℓ is the (tentative) distance to v from the root (a). If we do not show ℓ then ℓ(v) = ∞. At the first iteration we choose the root a as the unmarked vertex with smallest ℓ and update ℓ(b), ℓ(c). At the second iteration we choose c as the unmarked vertex with smallest ℓ and update ℓ(b), ℓ(d) and ℓ(e). 2 2 b/27 b/26 d/20 d 27 17 27 17 5 5 a/0 a/0 f f 14 3 14 3 8 7 8 7 13 13 12 11 12 11 e c/12 c/12 e/25 4 4 At the third iteration we choose d and update ℓ(b), ℓ(e) and ℓ(f ), and at the fourth iteration we choose e and update ℓ(f ). 2 2 b/25 d/20 b/25 d/20 27 17 5 a/0 14 8 7 c/12 4 14 11 8 f /34 7 3 13 12 e/23 17 5 a/0 3 13 12 27 f /37 c/12 4 11 e/23 At the fifth iteration we choose b and do not change ℓ, and at the sixth and final iteration we choose f and do not change ℓ. Now all vertices are marked with their distance from a, and shortest paths from a are as shown. 2 2 b/25 27 d/20 17 5 a/0 14 8 c/12 4 14 11 c/12 3 17 8 f /34 7 3 13 12 e/23 d/20 5 a/0 3 13 12 27 f /34 7 2 b/25 4 11 e/23