Generate nodes in strongly connected components of graph.
Parameters: G (NetworkX Graph) – An directed graph. Returns: comp – A generator of sets of nodes, one for each strongly connected component of G. Return type: generator of sets Raises: NetworkXNotImplemented: – If G is undirected.
Generate a sorted list of strongly connected components, largest first.
>>> G = nx.cycle_graph(4, create_using=nx.DiGraph()) >>> G.add_cycle([10, 11, 12]) >>> [len(c) for c in sorted(nx.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.strongly_connected_components(G), key=len)
Uses Tarjan’s algorithm with Nuutila’s modifications. Nonrecursive version of algorithm.
 Depth-first search and linear graph algorithms, R. Tarjan SIAM Journal of Computing 1(2):146-160, (1972).  On finding the strongly connected components in a directed graph. E. Nuutila and E. Soisalon-Soinen Information Processing Letters 49(1): 9-14, (1994)..