TreeGraphQ

TreeGraphQ[g]

yields True if the graph g is a tree and False otherwise.

Details

  • A tree is a connected graph with no cycles.

Examples

open allclose all

Basic Examples  (2)

Test whether a graph is a tree:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=

A graph with cycles is not a tree:

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

Scope  (6)

Properties & Relations  (10)

Possible Issues  (1)

See Also

Graph  DirectedGraph  TreeGraph  ConnectedGraphQ  AcyclicGraphQ

Introduced in 2010
(8.0)