Chapter 12

Three Algorithms on Graphs

[14/100%]
Show
LaTeX
Problem 200

Construct a minimum spanning tree for the undirected graph G=(V,E)\mathfrak {G}=(V, E) with vertex set V={v1,v2,v3,v4,v5,v6,v7,v8,v9}V=\left\{ v_{1}, v_{2}, v_{3}, v_{4}, v_{5}, v_{6}, v_{7}, v_{8}, v_{9}\right\} and edge set E={(v1,v2;18),(v1,v3;2),(v3,v2;4),(v3,v4;6),(v3,v5;8),(v4,v6;5),(v5,v4;4),(v6,v1;7),(v6,v8;4),(v6,v7;3),(v7,v5;1),(v7,v8;7),(v8,v1;5),(v8,v9;3),(v9,v1;1)}E=\left\{ \left(v_{1}, v_{2} ; 18\right),\left(v_{1}, v_{3} ; 2\right),\left(v_{3}, v_{2} ; 4\right),\left(v_{3}, v_{4} ; 6\right),\left(v_{3}, v_{5} ; 8\right),\left(v_{4}, v_{6} ; 5\right),\left(v_{5}, v_{4} ; 4\right),\left(v_{6}, v_{1} ; 7\right),\left(v_{6}, v_{8} ; 4\right),\left(v_{6}, v_{7} ; 3\right),\left(v_{7}, v_{5} ; 1\right),\left(v_{7}, v_{8} ; 7\right),\left(v_{8}, v_{1} ; 5\right),\left(v_{8}, v_{9} ; 3\right),\left(v_{9}, v_{1} ; 1\right)\right\}. The third parameter in brackets is the edge weight.

?
Problem 201

Let ee be an edge of maximum weight in some simple cycle CC of the graph G=(V,E)\mathfrak {G}=(V, E). Prove that

?
(a)

there exists a minimum spanning tree of the graph G′=(V,E\{e})\mathfrak {G}^{\prime }=(V, E \backslash \left\{ e\right\} ) which is also a minimum spanning tree of the graph G\mathfrak {G};

(b)

if CC has no other edges of the same weight, then no minimum spanning tree contains ee.

Problem 202

Let T=(V,T)\mathfrak {T}=(V, T) be a minimum spanning tree for a weighted undirected graph G=(V,E)\mathfrak {G}=(V, E) with nn vertices, cc an edge labeling. Let (e1,e2,…,en−1)(e_{1}, e_{2}, \ldots , e_{n-1}) be the sequence of edges of TT, ordered by increasing c(ei)c\left(e_{i}\right). Let T′\mathfrak {T}^{\prime } be an arbitrary spanning tree for G\mathfrak {G} with edges (d1,d2,…,dn−1)\left(d_{1}, d_{2}, \ldots , d_{n-1}\right), ordered by increasing c(di)c\left(d_{i}\right). Show that c(ei)⩽c(di)c\left(e_{i}\right) \leqslant c\left(d_{i}\right) for all i=1,…,n−1i=1, \ldots , n-1. Hint. Consider the forest of trees Ti,m\mathfrak {T}_{i, m} consisting of edges ej,j<ie_{j}, j<i, and edges dℓ,ℓ⩽id_{\ell }, \ell \leqslant i.

?
Problem 203

A drawback of Kruskal's algorithm is the need to check for the presence of cycles at each step, which is itself a fairly difficult task. The following algorithm was independently proposed by V. Jarník, R. Prim, and E. Dijkstra.

  1. Choose an arbitrary vertex aa; it is itself a tree (without edges).

  2. At each step, add to the existing tree the edge of least weight, one of whose vertices belongs to the tree and the other does not. Prove the correctness of this algorithm for connected graphs, by analogy with Theorem 80 (Correctness of Kruskal’s algorithm): the result of running Kruskal’s algorithm is a minimum spanning tree of the input graph G=(V,E)\mathfrak {G}=(V, E) with edge-labeling function cc.

?
Problem 204

Let T=(V,T)\mathfrak {T}=(V, T) be a depth-first spanning tree constructed by the depth-first search algorithm for the graph G=(V,E)\mathfrak {G}=(V, E). Prove that for every back edge (u,v)∈E\T(u, v) \in E \backslash T, either uu is an ancestor of vv in T\mathfrak {T}, or vv is an ancestor of uu in T\mathfrak {T}.

?
Problem 205

Modify the depth-first search algorithm so that it computes Up⁡[v]\operatorname {Up}[v] and prints the list of all bridges of the graph.

?
Problem 206

Starting from vertex v1v_{1}, traverse (number) the vertices of the given undirected graph G=(V,E)\mathfrak {G}=(V, E) using the depth-first search algorithm and construct the tree of this traversal. V={v1,v2,v3,v4,v5,v6,v7,v8,v9,v10},E={(v1,v2),(v1,v4),(v1,v8),(v7,v8),(v2,v9),(v9,v5),(v3,v8),(v6,v3),(v3,v7),(v6,v7),(v10,v9),(v10,v5)}V=\left\{ v_{1}, v_{2}, v_{3}, v_{4}, v_{5}, v_{6}, v_{7}, v_{8}, v_{9}, v_{10}\right\} , E=\left\{ \left(v_{1}, v_{2}\right),\left(v_{1}, v_{4}\right),\left(v_{1}, v_{8}\right),\left(v_{7}, v_{8}\right),\left(v_{2}, v_{9}\right),\left(v_{9}, v_{5}\right),\left(v_{3}, v_{8}\right),\left(v_{6}, v_{3}\right),\left(v_{3}, v_{7}\right),\left(v_{6}, v_{7}\right),\left(v_{10}, v_{9}\right),\left(v_{10}, v_{5}\right)\right\}. Which back edge e∈E\Te \in E \backslash T and cycle in G\mathfrak {G} were discovered first in this traversal? Compute the value Up⁡[v]\operatorname {Up}[v] for each vertex vv and determine all bridges of the graph G\mathfrak {G}. Assume that all adjacency lists are ordered by increasing vertex number, and the vertex with the smallest number is chosen.

?
Problem 207

Modify the depth-first search algorithm so that it allows listing all connected components of an undirected graph.

?
Problem 208

If in a directed graph G=(V,E)\mathfrak {G}=(V, E) there exists a vertex rr from which all other vertices are reachable, then for it too one can define the notion of a spanning (now directed) tree: a tree T=(V,T)\mathfrak {T}=(V, T) with root rr. Determine which of the spanning tree construction algorithms can be adapted for constructing a spanning tree in a directed graph: Kruskal's algorithm, the Jarník-Prim-Dijkstra algorithm, the depth-first search algorithm.

?
Problem 209

For the following weighted graph G=(V,E)\mathfrak {G}=(V, E) and vertex a∈Va \in V, determine the lengths of the shortest paths from aa to the other vertices of G\mathfrak {G} and construct the tree of these paths. Here V={a,b,c,d,e,f},E={(a,b;154),(a,c;17),(a,d;214),(a,e;63),(b,d;25),(c,e;33),(c,d;192),(c,b;123),(d,f;5),(e,f;140),(d,e;10)}V=\left\{ a, b, c, d, e, f\right\} , E=\left\{ (a, b ; 154),(a, c ; 17),(a, d ; 214), (a, e; 63), (b, d; 25), (c, e; 33), (c, d; 192), (c, b; 123), (d, f; 5), (e, f; 140), (d, e; 10)\right\}.

?
Problem 210

Where in the proof of correctness of Dijkstra's algorithm is the nonnegativity of edge weights used? Give an example of a graph (with negative weights) for which Dijkstra's algorithm gives an incorrect answer.

?
Problem 211

Theorem 83 (Correctness of Dijkstra's algorithm): Dijkstra's algorithm constructs the shortest-path tree from vertex aa to every vertex reachable from it, and for each such vertex vv determines the length D[v]D[v] of the shortest path to it from aa. In the proof, by induction on kk: let RkR_{k}, DkD_{k}, FkF_{k} denote the value of RR and the contents of the arrays DD, FF after kk iterations of the algorithm's main loop, and let wkw_{k} be the vertex chosen at step k+1k+1.

Show that in the proof of the induction step of Theorem 83 on p. 248, the vertex wkw_{k} can only be second-to-last on the shortest path from aa to u∈V\(Rk∪{wk})u \in V \backslash \left(R_{k} \cup \left\{ w_{k}\right\} \right).

?
Problem 212

How many times can the value D[v]D[v] change for a single vertex vv during the execution of Dijkstra's algorithm on a graph with six vertices? Give an example for each possible case.

?
Problem 213

Let a vertex aa be chosen in a graph G\mathfrak {G}, and suppose that for every vertex v∈Vv \in V reachable from aa there is a unique shortest path from aa to vv. Prove that the edges of all these paths form a directed tree rooted at aa.

?