Skip to main content
`Ctrl`+`K`

# number_connected_components

number_connected_components(G)

  Returns the number of connected components.

  Parameters:
    G NetworkX graph

      An undirected graph.

  Returns:
    n integer

      Number of connected components

  Raises:
    NetworkXNotImplemented

      If G is directed.

  See also

  `connected_components`
  `number_weakly_connected_components`
  `number_strongly_connected_components`

  Notes

  For undirected graphs only.

  Examples

      >>> G = nx.Graph([(0, 1), (1, 2), (5, 6), (3, 4)])
      >>> nx.number_connected_components(G)
      3