# connected_components¶

connected_components(G)[source]

Generate connected components.

Parameters: G : NetworkX graph An undirected graph comp : generator of lists A list of nodes for each component of G.

See also

strongly_connected_components

Notes

For undirected graphs only.

Examples

Generate a sorted list of connected components, largest first.

>>> G = nx.path_graph(4)
>>> G.add_path([10, 11, 12])
>>> sorted(nx.connected_components(G), key = len, reverse=True)
[[0, 1, 2, 3], [10, 11, 12]]