gives the weakly connected components of the graph g.


gives the weakly connected components that include at least one of the vertices v1, v2, .


gives the connected components that include a vertex that matches the pattern patt.


uses rules vw to specify the graph g.

Details and Options

  • WeaklyConnectedComponents returns a list of components {c1,c2,}, where each component ci is given as a graph.
  • Vertices u and v are in the same component ci if there is a sequence of edges joining u and v.
  • Components ci are ordered by their length, with the largest component first.
  • WeaklyConnectedGraphComponents works with undirected graphs, directed graphs, multigraphs, and mixed graphs.


open allclose all

Basic Examples  (1)

Give the weakly connected components of a graph:

Highlight the components:

Scope  (8)

WeaklyConnectedGraphComponents works with undirected graphs:

Directed graphs:


Mixed graphs:

Use rules to specify the graph:

Select weakly connected graph components that include at least one of the specified vertices:

Use patterns to select a subset of weakly connected graph components:

WeaklyConnectedGraphComponents works with large graphs:

Applications  (1)

A frog in a lily pond is able to jump 1.5 feet to get from one of the 25 lily pads to another. Model the frog's jumping network from the lily leaf density and SpatialGraphDistribution:

Sample a random pond:

Find the largest collection of lily pads the frog can jump between:

Find the number of times the frog would have to swim to visit all lily pads:

Properties & Relations  (3)

For undirected graphs, connected and weakly connected components are identical:

Use WeaklyConnectedGraphQ to test whether a graph is weakly connected:

Weakly connected graph components are ordered by their vertex count, with the largest component first:

Introduced in 2016