Find Strongly Connected Components in a Directed Graph: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 19: Line 19:
2. Do the first [[Graph_Search#DFS_Recursive_Algorithm_Pseudocode|depth-first search]] pass on the reversed graph G<sup>rev</sup>. The practical implementation should run DFS on the original graph G but going in the opposite direction of the arcs, backwards. This pass computes an ordering of nodes that allows the second pass, while starting in the given order, to discover the strongly connected components. Let f(v) = "finishing time" of each v ∈ V.
2. Do the first [[Graph_Search#DFS_Recursive_Algorithm_Pseudocode|depth-first search]] pass on the reversed graph G<sup>rev</sup>. The practical implementation should run DFS on the original graph G but going in the opposite direction of the arcs, backwards. This pass computes an ordering of nodes that allows the second pass, while starting in the given order, to discover the strongly connected components. Let f(v) = "finishing time" of each v ∈ V.


3. Do the second [[Graph_Search#DFS_Recursive_Algorithm_Pseudocode|depth-first search]] pass again, on the original graph G. In this pass we use the order computed by the first pass and we discover the strongly connected components one by one. The "right" order is to go through the vertices in the decreasing order of the "finishing time" computed during the first pass.
3. Do the second [[Graph_Search#DFS_Recursive_Algorithm_Pseudocode|depth-first search]] pass again, on the original graph G. In this pass we use the order computed by the first pass and we discover the strongly connected components one by one. The "right" order is to go through the vertices in the decreasing order of the "finishing time" computed during the first pass. During this second pass we will label each node with what we call a "leader". The idea is all nodes in the same strongly connected component will be labeled with the same leader node.

Revision as of 22:24, 4 October 2021

External

Internal

Overview

Finding strongly connected components in a directed graph is a form of clustering heuristics: strongly connected components represent clusters where the objects represented by the vertices are clustered in some way.

Strongly connected components of a directed graph can be computed with Kosaraju's Two-Pass algorithm, which consists of two passes of depth-first search. The key idea of the algorithm is that for directed graphs, starting a depth-first search from the "right" nodes discovers strongly connected components, while starting from the "wrong" nodes may discover the entire graph, which is not useful. The first pass of the algorithm computes the right order in which to use the nodes as start nodes in the second depth-first search pass.

Kosaraju's Two-Pass Algorithm

The algorithm has three steps:

1. Reverse all of the arcs of the given graph. Let Grev = G with all arcs revered.

2. Do the first depth-first search pass on the reversed graph Grev. The practical implementation should run DFS on the original graph G but going in the opposite direction of the arcs, backwards. This pass computes an ordering of nodes that allows the second pass, while starting in the given order, to discover the strongly connected components. Let f(v) = "finishing time" of each v ∈ V.

3. Do the second depth-first search pass again, on the original graph G. In this pass we use the order computed by the first pass and we discover the strongly connected components one by one. The "right" order is to go through the vertices in the decreasing order of the "finishing time" computed during the first pass. During this second pass we will label each node with what we call a "leader". The idea is all nodes in the same strongly connected component will be labeled with the same leader node.