# GraphTree GraphTree[g]

constructs a tree from the tree graph g.

GraphTree[g,root]

specify what vertex to use as root.

GraphTree[g,root,h]

applies h to each vertex to get the corresponding data and ordering of subtrees.

# Details • In GraphTree[g], g must be a valid graph object for which TreeGraphQ gives True.
• GraphTree gives a Tree object with subtrees containing the vertices of graph.
• By default, GraphTree[g] uses the vertex with the largest VertexOutComponent as root.
• In GraphTree[g,root], the direction of edges is ignored.
• In GraphTree[g,root,h], the subtree for a vertex v is specified by h[v], which should return a pair {data,expr}. For siblings {datai,expri}, the datai give the data in the subtrees, and the siblings are sorted by the expri.
• GraphTree[TreeGraph[tree],{data,{}},Identity] is equivalent to tree, where TreeData[tree] gives data.

# Examples

open allclose all

## Basic Examples(2)

Transform a directed graph into a Tree object:

Specify an alternate root:

Convert an undirected graph into a Tree object:

## Scope(4)

Transform a CompleteKaryTree graph into a tree:

Specify the root vertex:

Sort the siblings in reverse order:

Convert a StarGraph object into a tree:

Transform a TreeGraph object into a tree:

## Properties & Relations(3)

GraphTree can only transform TreeGraphQ objects:

If the graph is not TreeGraphQ, then GraphTree will fail: Use TreeGraph to convert a tree into a Graph:

GraphTree[TreeGraph[tree],{data,{}},Identity] is equivalent to tree, where TreeData[tree] gives data:

The root vertex is of the form {data,{}}:

Reconstruct the tree, sorting siblings by their position: