PathGraphQ[g]
PathGraphQ
PathGraphQ[g]
Examples
open all close allBasic Examples (2)
Test whether a graph is a path:
Graph[{12, 23, 34}]PathGraphQ[%]The vertex degree is at most 2:
VertexDegree[%%]A complete graph is not a path:
CompleteGraph[5]PathGraphQ[%]The vertex degree is greater than 2:
VertexDegree[%%]Scope (6)
PathGraphQ works with undirected graphs:
PathGraphQ[[image]]PathGraphQ[[image]]PathGraphQ[[image]]PathGraphQ[[image]]PathGraphQ gives False for anything that is not a path graph:
PathGraphQ[x]PathGraphQ[Graph[garbage]]g = GridGraph[{1, 10000}];PathGraphQ[g]//Timing{VertexCount[g], EdgeCount[g]}Properties & Relations (8)
A path graph is loop-free if it has more than one vertex:
Graph[{12, 23, 22}]{PathGraphQ[%], LoopFreeGraphQ[%]}A path graph does not necessarily have edges:
PathGraphQ[Graph[{1}, {}]]A path graph that starts and ends in the same vertex is a cycle graph:
CycleGraph[5]PathGraphQ[%]A path graph with no repeated vertices is a tree:
g = Graph[{12, 23, 34}];{TreeGraphQ[g], PathGraphQ[g]}An acyclic path graph is simple:
g = GridGraph[{1, 4}]{PathGraphQ[g] && AcyclicGraphQ[g], SimpleGraphQ[g]}BipartiteGraphQ[g]GridGraph[{1,…,1,k,1,…,1}] are all path graphs:
PathGraphQ[GridGraph[{1, 4}]]PathGraphQ[GridGraph[{4, 1}]]PathGraphQ[GridGraph[{1, 4, 1}]]A path graph is connected and each vertex has at most degree 2:
g = CycleGraph[5]{ConnectedGraphQ[g], PathGraphQ[g]}Max[VertexDegree[g]]The line graph of a path
is isomorphic to
:
PathGraph[Range[8]]IsomorphicGraphQ[LineGraph[%], PathGraph[Range[7]]]Possible Issues (1)
PathGraphQ gives False for non-explicit graphs:
PathGraphQ[CycleGraph[n]]PathGraphQ[CompleteGraph[n]]Related Guides
History
Text
Wolfram Research (2010), PathGraphQ, Wolfram Language function, https://reference.wolfram.com/language/ref/PathGraphQ.html.
CMS
Wolfram Language. 2010. "PathGraphQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PathGraphQ.html.
APA
Wolfram Language. (2010). PathGraphQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PathGraphQ.html
BibTeX
@misc{reference.wolfram_2026_pathgraphq, author="Wolfram Research", title="{PathGraphQ}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/PathGraphQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_pathgraphq, organization={Wolfram Research}, title={PathGraphQ}, year={2010}, url={https://reference.wolfram.com/language/ref/PathGraphQ.html}, note=[Accessed: 12-June-2026]}