Package org.graph4j.connectivity
Class TarjanStrongConnectivity
java.lang.Object
org.graph4j.DirectedGraphAlgorithm
org.graph4j.connectivity.TarjanStrongConnectivity
- All Implemented Interfaces:
StrongConnectivityAlgorithm
public class TarjanStrongConnectivity
extends DirectedGraphAlgorithm
implements StrongConnectivityAlgorithm
Tarjan's strongly connected components algorithm is an algorithm in graph
theory for finding the strongly connected components (SCCs) of a directed
graph. It runs in linear time, matching the time bound for alternative
methods including Kosaraju's algorithm and the path-based strong component
algorithm.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from class org.graph4j.DirectedGraphAlgorithm
graph, stronglyConnected -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcompute(boolean checkOnly) Each strongly connected component is contracted to a single vertex, the resulting graph is a directed acyclic graph, the condensation.booleanReturnstrueif the digraph is strongly connected.
-
Constructor Details
-
TarjanStrongConnectivity
-
-
Method Details
-
isStronglyConnected
public boolean isStronglyConnected()Description copied from class:DirectedGraphAlgorithmReturnstrueif the digraph is strongly connected.- Specified by:
isStronglyConnectedin interfaceStrongConnectivityAlgorithm- Overrides:
isStronglyConnectedin classDirectedGraphAlgorithm- Returns:
trueif the digraph is strongly connected.
-
getStronglyConnectedSets
- Specified by:
getStronglyConnectedSetsin interfaceStrongConnectivityAlgorithm- Returns:
- a list of vertex sets, each representing the vertices of a strongly connected component.
-
getStronglyConnectedComponents
- Specified by:
getStronglyConnectedComponentsin interfaceStrongConnectivityAlgorithm- Returns:
- a list of digraphs, each representing a strongly connected component.
-
compute
protected void compute(boolean checkOnly) -
createCondensation
Description copied from interface:StrongConnectivityAlgorithmEach strongly connected component is contracted to a single vertex, the resulting graph is a directed acyclic graph, the condensation. Each vertex of the condensation is labeled with the corresponding strongly connected component. Each edge vu of the condensation is labeled with the number of edges from the component of v to to the component of u in the original digrpah.- Specified by:
createCondensationin interfaceStrongConnectivityAlgorithm- Returns:
- the condensation digraph.
-