This documents the development version of NetworkX. Documentation for the current release can be found here.
Generate nodes in strongly connected components of graph.
- GNetworkX Graph
A directed graph.
- compgenerator of sets
A generator of sets of nodes, one for each strongly connected component of G.
If G is undirected.
Uses Kosaraju’s algorithm.
Generate a sorted list of strongly connected components, largest first.
>>> G = nx.cycle_graph(4, create_using=nx.DiGraph()) >>> nx.add_cycle(G, [10, 11, 12]) >>> [ ... len(c) ... for c in sorted( ... nx.kosaraju_strongly_connected_components(G), key=len, reverse=True ... ) ... ] [4, 3]
If you only want the largest component, it’s more efficient to use max instead of sort.
>>> largest = max(nx.kosaraju_strongly_connected_components(G), key=len)