Exercises 22.5-Introduction to Algorithms. English 3rd Edition
While reading recently, feel some practice lack of reference, so according to the partial summary of their own answers, but also to strengthen the learning process.
If there is any shortage or doubt, please correct me.
Exercises 22.5-1How can the number of strongly connected components of a graph change if a Newedge is added? Each strongly connected component can be treated as a vertex, a strong connected graph, a vertex in the graph Quantity is the number of strongly connected components. If the newly added edge is inside the vertex (that is, pointing to itself), or if the edges between the existing vertices are repeated, the quantity does not change. If the newly added edge causes the graph to form a ring, so that the vertices within the ring form a new strongly connected component, the number is reduced by n, n = (number of vertices within the ring-1).
Exercises 22.5-2Show How the procedure strongly-connected-components works on thegraph for figure 22.6. Specifically, show the finishing times computed in line 1 andthe forest produced on line 3. Assume the loop of lines 5–7 of DFS considersvertices in alphabetical order and that the adjacency lists is in alpha Betical order. Alphabetically sorted loops and adjacency tables can be derived from the first DFS access vertex order, as follows (Q (S (V (w) v) s) (t (x (z, z) x) (y, y) t) q) (R (U, u) r) Finishing Ti Me:f (R), F (U), R (Q), F (t), f (Y), f (x), F (z), F (s) 7, F (v) 6, F (w) 5. According to finishing time descending, and reversing the edge in, the second DFS accesses the vertex order as follows (R, R) * (U, u) * (q (Y (t, t) y) * (x (z, z) x) * (S (w (V, v) W) s) each unrelated bracket (with a * interval) within the vertex, representing the tree generated by line 3 (i.e. strong connected components)
Answer:dfs (G) Forest: (where red is the tree edge)
Strong connectivity Component results:
Exercises 22.5-3Professor Bacon claims the algorithm for strongly connected Componentswould is simpler if it used the original (inste Ad of the transpose) graph in Thesecond Depth-first search and scanned the vertices in order of
increasingFinishingtimes. Does This simpler algorithm always produce correct results? Imagine an ascending algorithm specified for the application, with a, B, C three vertices, a->b, b->a, and b->c three edges. If first DFS starts with B, the access vertex order is (b (A, a) (c, c) b) liters Order finishing Time is a, C, B. This second DFS should start with a, the algorithm shows a, B, C is a strongly connected component, and the actual situation is not. The algorithm cannot guarantee universality, only when the special vertex is selected as the starting point, and the specified adjacency In the case of table order, the result is probably correct.
Exercises 22.5-4Prove that for any directed graph G, we have ((GT) SCC) T = (G) SCC. That's, thetranspose of the component graph of GT is the same as the component graph of G. In Figure G, the vertices in the same component can be interconnected. In the figure GT, the edges in the assembly are reversed, but their vertices can still be interconnected, which is unaffected by the reversal of the edges between the components, and no new components are formed. So ((GT) SCC) T = (g) SCC, i.e. the strong connected components of the GT and G are the same.
Exercises 22.5-5Give a O (v + E)-time algorithm to compute the component graph of a directedgraph G = (V, E). Make sure, there is at most one edge between and verticesin the component graph your algorithm produces. (1) Firs T DFS (G) if v Fini sh orderlist.push_front (v) //orderlist Yes Finishing time descending queue times O (v + E) (2) for each V in v for each x in v.adj x.adj.push_back (v) Instant GT time O (v + E) (3) Second DFS (GT) &nbs P for v in order of orderlist map v to SCC //SCC is a strong connectivity component for each x in v.adj if X.color = Color_black //represents this edge (V, x) is the edge between the strongly connected components  &N Bsp if x non-exist in Scc.adj //total search time during DFS (GT) O (E) Scc.adj.push_back (x) to find SCC and Scc.adj time O (v + e), so algorithm time complexity O (v + e) .
Exercises 22.5-6Given a directed graph G = (V, e), explain how to create another graph G ' = (V, e ') such this (a) G ' has the same strongly Connected Components as G, (b) G ' have the same component graph as G, and (c) E ' is as small as possible. Describe afast algorithm to compute G ' (1) determines each SCC vertex collection, as well as all edge sets between the SCC Es (without the edges within the SCC), the time O (V + E) (2) within each SCC is assumed to be a bit V1, v2, ..., VN, so that it forms a ring v1-> v2, V2->v3, ..., Vn->v1, Time O (V) (3) Here assume that the number of SCC is n, generating n * n matrices. For Es Middle side (VI, VJ), assuming VI belongs to SCCI, VJ belongs to SCCJ. If N[SCCI][SCCJ] = = 0, then (vi, VJ) is saved to E ', if N[SCCI][SCCJ] = = 1, the Edge is skipped. Calculates all the edges in the Es in turn, where the time O (E '), and O (E ') < O (e), so the algorithm time complexity O (V + E)
Exercises 22.5-7A directed graph G = (V, E) is
semiconnectedIf, for all pairs of vertices u, v∈v, we have u ~> v or v ~> U. Give a efficient algorithm to determine whetheror Not G is semiconnected. Prove that your algorithm is correct, and analyze itsrunning time. Strong connectivity component algorithm, according to the 2nd time DFS (GT) strong connectivity component generation sequence number, assuming is SCC1, SCC2, ..., SCCN if there is an edge (SCC1, SCC2), (SCC2, SCC3), ..., (SCCn-1, SCCN), that is, between components The edge forms a linear chain, then the figure G is semiconnected. explained in detail later. (1) Strong connected component graph algorithm, time O (v+e) (2) According to the strong connected component SCC sequence number, assuming that it is SCC1, SCC2, ..., SCCN, and find the component SCC adjacency table, this step can be completed in (1), so time O (v+e) (3) Traversal SC C adjacency table, if for the range i = 1, 2, ..., n-1, strong connected components Scci.adj exist scci+1, both with the Edge (Scci, scci+1), strong connected component diagram is a linear chain, then G = (V, E) is semiconnected , Time O (v+e). Detailed explanation, according to the theory of the algorithm support, scci+1 does not exist to Scci side, if not (Scci, scci+1), the two can not reach each other, that is, does not conform to the concept of G is semiconnected. Algorithm time complexity O (v+e)
Introduction to Algorithms exercises 22.5 (reprint)