Skip to content

IsConnectedGraph ​

Whether a Graph is connected — a single component; strongly connected when it has directed edges.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageConnectedGraphQ✓
IsConnectedGraph(g)true iff the graph is one component, respecting edge direction (false for a graph with no vertices).
Typed signatures
TypePackageApplies
(value) -> booleancombinatoricsalways

Domain: Collections

Details
  • Wolfram calls this ConnectedGraphQ; this library uses the Is… spelling everywhere.
  • Respects direction, as Wolfram's ConnectedGraphQ does: a directed graph is connected only when it is strongly connected, so a single directed edge is not. IsTreeGraph still reads the underlying undirected graph.

Examples

Basic #
live ↗
InIsConnectedGraph(PetersenGraph())\mathrm{IsConnectedGraph}(\mathrm{PetersenGraph}())OutTrue\mathrm{True}
live ↗
InIsConnectedGraph(Graph([1,2,3,4],[UndirectedEdge(1,2),UndirectedEdge(3,4)]))\mathrm{IsConnectedGraph}(\mathrm{Graph}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack, \bigl\lbrack\mathrm{UndirectedEdge}(1, 2), \mathrm{UndirectedEdge}(3, 4)\bigr\rbrack))OutFalse\mathrm{False}

1 reaches 3 but 3 cannot get back: one weak piece, not strongly connected

live ↗
InIsConnectedGraph(Graph([1,2,3],[DirectedEdge(1,2),DirectedEdge(2,1),DirectedEdge(2,3)]))\mathrm{IsConnectedGraph}(\mathrm{Graph}(\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack\mathrm{DirectedEdge}(1, 2), \mathrm{DirectedEdge}(2, 1), \mathrm{DirectedEdge}(2, 3)\bigr\rbrack))OutFalse\mathrm{False}
live ↗
InIsConnectedGraph(Graph([1,2,3],[DirectedEdge(1,2),DirectedEdge(2,3),DirectedEdge(3,1)]))\mathrm{IsConnectedGraph}(\mathrm{Graph}(\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack\mathrm{DirectedEdge}(1, 2), \mathrm{DirectedEdge}(2, 3), \mathrm{DirectedEdge}(3, 1)\bigr\rbrack))OutTrue\mathrm{True}
About
Examples4
Checked againstWolfram Language 4 agree
CrosswalkWolfram Language

See also: ConnectedComponents, IsTreeGraph