Skip to content

IsPathGraph ​

Whether a Graph is a simple path — a single chain of vertices, each joined once to the next.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguagePathGraphQ!
IsPathGraph(g)true iff g is simple (no self-loop, no repeated edge) and its underlying graph is a path.
Typed signatures
TypePackageApplies
(value) -> booleancombinatoricsalways

Domain: Collections

Details
  • Wolfram calls this PathGraphQ; this library uses the Is… spelling everywhere (see IsConnectedGraph's own note).

Examples

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

A single vertex is the trivial path

live ↗
InIsPathGraph(Graph([1],[]))\mathrm{IsPathGraph}(\mathrm{Graph}(\bigl\lbrack1\bigr\rbrack, \bigl\lbrack\bigr\rbrack))OutTrue\mathrm{True}

A 1×41\times4 grid is a path on four vertices

live ↗
InIsPathGraph(GridGraph([1,4]))\mathrm{IsPathGraph}(\mathrm{GridGraph}(\bigl\lbrack1, 4\bigr\rbrack))OutTrue\mathrm{True}

Transposed dimensions give the same path

live ↗
InIsPathGraph(GridGraph([4,1]))\mathrm{IsPathGraph}(\mathrm{GridGraph}(\bigl\lbrack4, 1\bigr\rbrack))OutTrue\mathrm{True}

Trailing singleton dimensions leave it a path

live ↗
InIsPathGraph(GridGraph([1,4,1]))\mathrm{IsPathGraph}(\mathrm{GridGraph}(\bigl\lbrack1, 4, 1\bigr\rbrack))OutTrue\mathrm{True}
About
Examples6
Checked againstWolfram Language 5 agree1 differ
CrosswalkWolfram Language

See also: PathGraph, IsTreeGraph, IsAcyclicGraph