This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

TreeGraphQ

TreeGraphQ[g]
yields True if the graph g is a tree and False otherwise.
  • A tree is a connected graph with no cycles.
Test whether a graph is a tree:
A graph with cycles is not a tree:
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]=
TreeGraphQ gives False for anything that is not a tree graph:
Test large graphs:
A tree graph can be a simple graph:
A tree graph can be a weighted graph:
A star is a special tree with as many leaves as possible:
A path graph with no repeated vertices is a tree with two leaves:
A graph with self-loops is not a tree graph:
A graph with cycles is not a tree graph:
A disconnected graph is not a tree graph:
A tree graph with vertices has edges:
A tree graph is a bipartite graph:
A tree graph is not Hamiltonian:
TreeGraphQ gives False for non-explicit graphs:
New in 8