Macaulay2 » Documentation
Packages » Graphs :: connectedComponents(Graph)
next | previous | forward | backward | up | index | toc

# connectedComponents(Graph) -- Computes the connected components of a graph

- Function: connectedComponents
- Usage:
    `C = connectedComponents G`
- Inputs:
  - G, a graph,
- Outputs:
  - C, a list, The list of connected components of G

## Description

A connected component is a list of vertices of a graph that are connected, in other words there exists a path of edges between any two vertices in the component.

    i1 : G = graph(toList(1..8),{{1,2},{2,3},{3,4},{5,6}});

    i2 : connectedComponents G

    o2 = {{1, 2, 3, 4}, {5, 6}, {7}, {8}}

    o2 : List

## See also

- isConnected -- determines whether a graph is connected
- numberOfComponents -- computes the number of connected components of a graph

## Ways to use this method:

- connectedComponents(Graph) -- Computes the connected components of a graph

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Graphs.m2:3221:0.