




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The problem of determining if a directed graph is strongly connected and how to find its strongly connected components. An algorithm based on depth-first search (dfs) and the concept of a component digraph. It also introduces the idea of ordering the vertices according to their finish times in a dfs to visit the strong components in reverse topological order.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





We consider an important connectivity problem with digraphs. When diagraphs are used in communication and transportation networks, people want to know that their networks are complete. Complete in the sense that that it is possible from any location in the network to reach any other location in the digraph.
A digraph is strongly connected if for every pair of vertices u, v ∈ V, u can reach v and vice versa. We would like to write an algorithm that determines whether a digraph is strongly connected. In fact, we will solve a generalization of this problem, of computing the strongly connected components of a digraph.
We partition the vertices of the digraph into subsets such that the induced sub graph of each subset is strongly connected. We say that two vertices u and v are mutually reachable if u can reach v and vice versa. Consider the directed graph in Figure 8.32. The strong components are illustrated in Figure 8.33.
Figure 8.32: A directed graph
Figure 8.33: Digraph with strong components
It is easy to see that mutual reach ability is an equivalence relation. This equivalence relation partitions the vertices into equivalence classes of mutually reachable vertices and these are the strong components. If we merge the vertices in each strong component into a single super vertex , and join two super vertices (A, B) if and only if there are vertices u ∈ A and v ∈ B such that (u, v) ∈ E, then the resulting digraph is called the component digraph. The component digraph is necessarily acyclic. The is illustrated in Figure 8.34.
Figure 8.34: Component DAG of super vertices
Is there a way to order the DFS such that it true? Fortunately, the answer is “yes”. Suppose that you knew the component DAG in advance. (This is ridiculous, because you would need to know the strong components and this is the problem we are trying to solve.) Further, suppose that you computed a reversed topological order on the component DAG. That is, for edge (u, v) in the component DAG, then v comes before u. This is presented in Figure 8.37. Recall that the component DAG consists of super vertices.
Figure 8.37: Reversed topological sort of component DAG
Now, run DFS, but every time you need a new vertex to start the search from, select the next available vertex according to this reverse topological order of the component digraph. Here is an informal justification. Clearly once the DFS starts within a given strong component, it must visit every vertex within the component (and possibly some others) before finishing. If we do not start in reverse topological, then the search may “leak out” into other strong components, and put them in the same DFS tree. For example, in the Figure 8.36, when the search is started at vertex ‘a’, not only does it visit its component with ‘b’ and ‘c’, but it also visits the other components as well. However, by visiting components in reverse topological order of the component tree, each search cannot “leak out” into other components, because other components would have already have been visited earlier in the search. This leaves us with the intuition that if we could somehow order the DFS, so that it hits the strong components according to a reverse topological order, then we would have an easy algorithm for computing strong components. However, we do not know what the component DAG looks like. (After all, we are trying to solve the strong component problem in the first place). The trick behind the strong component algorithm is that we can find an ordering of the vertices that has essentially the necessary property, without actually computing the component DAG. We will discuss the algorithm without proof. Define G T to be the digraph with the same vertex set at G but in which all edges have been reversed in direction. This is shown in Figure 8.38. Given an adjacency list for G, it is possible to compute GT^ in Θ(V + E) time.
Figure 8.38: The digraph GT
Observe that the strongly connected components are not affected by reversal of all edges. If u and v are mutually reachable in G, then this is certainly true in GT. All that changes is that the component DAG is completely reversed. The ordering trick is to order the vertices of G according to their finish times in a DFS. Then visit the nodes of G T in decreasing order of finish times. All the steps of the algorithm are quite easy to implement, and all operate in Θ(V + E) time. Here is the algorithm:
The execution of the algorithm is illustrated in Figures 8.39, 8.40 and 8.41.
Figure 8.41: Final DFS with strong components of GT
The complete proof for why this algorithm works is in CLR. We will discuss the intuition behind why the algorithm visits vertices in decreasing order of finish times and why the graph is revered. Recall that the main intent is to visit the strong components in a reverse topological order. The problem is how to order the vertices so that this is true. Recall from the topological sorting algorithm, that in a DAG, finish times occur in reverse topological order (i.e., the first vertex in the topological order is the one with the highest finish time). So, if we wanted to visit the components in reverse topological order, this suggests that we should visit the vertices in increasing order of finish time, starting with the lowest finishing time.
This is a good starting idea, but it turns out that it doesn’t work. The reason is that there are many vertices in each strong component, and they all have different finish times. For example, in Figure 8.36, observe that in the first DFS, the lowest finish time (of 4) is achieved by vertex ‘c’, and its strong component is first, not last, in topological order.
However, there is something to notice about the finish times. If we consider the maximum finish time in each component, then these are related to the topological order of the component graph. In fact it is possible to prove the following (but we won’t).
Lemma: Consider a digraph G on which DFS has been run. Label each component with the maximum finish time of all the vertices in the component, and sort these in decreasing order.Then this order is a topological order for the component digraph.
For example, in Figure 8.36, the maximum finish times for each component are 18 (for { a, b, c }), 17 (for { d,e }), and 12 (for { f,g,h,i }). The order (18, 17, 12) is a valid topological order for the component digraph. The problem is that this is not what we wanted. We wanted a reverse topological order for the component digraph. So, the final trick is to
reverse the digraph. This does not change the component graph, but it reverses the topological order, as desired.