Tree
Tree[{subtree1,subtree2,…}]
represents a tree with a list of child subtrees subtreei.
Tree[data,subtrees]
represents a tree containing data in its root, with children given by subtrees.
Details

- Tree objects represent rooted, ordered, labeled trees. Standard examples include XML trees, file systems and Wolfram Language expressions.
- In Tree[data,subtrees], the subtrees are other Tree expressions or general expressions that are interpreted as leaves.
- Tree[…] displays in a notebook as a plot of a tree graph:
- Tree[…] is always converted to a standard form with structure Tree[data,subtrees].
- Tree[subtrees] is equivalent to Tree[Null,subtrees].
- Tree is treated as a raw object by functions like AtomQ.
- Options affecting individual tree elements or nodes include:
-
TreeElementLabel labels for subtree elements TreeElementStyle styles for subtree elements - Options affecting the entire tree include:
-
TreeLayout how to lay out subtrees and edges - Tree has all options shared by Graph and Graphics.

Examples
open allclose allBasic Examples (4)
Options (9)
Styling Individual Tree Elements (2)
Styling Entire Tree (4)
Tree Layout and Graphics Options (3)
Applications (8)
Create a tree from the hierarchy of files in a directory:
Define a function that extracts the tag from an XMLElement:
Define a function that yields the child elements of an XMLElement:
Convert an XMLElement object to a tree:
Convert an XML tree to an XMLElement:
Define a function that extracts the data from a JSON rule:
Define a function that extracts the children from a JSON rule:
Define a function that converts a TextElement object to a tree:
Define a function that yields the child elements of a TextElement:
Define a function that extracts the "GrammaticalUnit" from a TextElement:
Convert TextElement to a tree:
Convert a text tree to a TextElement:
Get a list of US cities with populations over 100,000:
Construct a graph giving the hierarchical clustering of the cities according to their geodetic positions:
Convert the clustering hierarchy from a Graph object to a Tree object:
For each leaf, obtain the geodetic position of a city from its index in the hierarchical clustering graph:
For each subtree representing a cluster, give the tree containing the spatial median of its children:
Obtain a tree of geodetic positions by using the position of a city for each leaf and the spatial median of the positions for each cluster:
Show the edges in this tree of geodetic positions on a map of the United States:
Create an association giving the dates of birth:
Define a function that compares two people, giving the person who was younger when they had their first child, together with that child and their age when that child was born:
Define a function that compares two siblings, giving the older sibling together with their date of birth, in addition to the youngest first-time parent among their descendants:
Define a function that gives the youngest first-time parent among a person's descendants, given the results for their children:
Find the youngest first-time parent in the tree, together with their first child and their age when the child was born:
Properties & Relations (6)
A root node of a tree does not need to have data:
RulesTree returns a Tree expression:
Check whether an expression with head Tree is a valid Tree object:
This is not a valid Tree object:
However, this is a valid Tree object that contains a child with an invalid Tree expression as data:
Construct a Tree expression with ExpressionTree:
Text
Wolfram Research (2021), Tree, Wolfram Language function, https://reference.wolfram.com/language/ref/Tree.html (updated 13).
CMS
Wolfram Language. 2021. "Tree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 13. https://reference.wolfram.com/language/ref/Tree.html.
APA
Wolfram Language. (2021). Tree. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Tree.html