PathGraphQ

PathGraphQ[g]
yields True if the graph g is a path and False otherwise.

DetailsDetails

  • An undirected path graph is a connected graph where each vertex has at most degree two.
  • A directed path graph is a connected graph where each vertex has at most in-degree one and at most out-degree one.

ExamplesExamplesopen allclose all

Basic Examples (2)Basic Examples (2)

Test whether a graph is a path:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

The vertex degree is at most 2:

In[3]:=
Click for copyable input
Out[3]=

A complete graph is not a path:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

The vertex degree is greater than 2:

In[3]:=
Click for copyable input
Out[3]=
New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »