Trees are fundamental data structures in mathematics and science used to represent nested structures, including hierarchical clustering in statistics, files and directories in filesystems, grammatical structure in text, evolutionary relationships in phylogenetic trees, decision trees, XML and even symbolic Wolfram Language expressions. The Wolfram Language provides a variety of built-in functions for constructing, traversing and computing with trees. Trees can be constructed from common tree-structured objects in the Wolfram Language, or general trees can be constructed using custom rules. Trees can contain any Wolfram Language expressions, which can be used to model rooted, ordered, labeled trees with arbitrary data. High-level functional programming constructs are provided for working with subtrees by position and level, as well as recursive traversals and computations.

Construction and Representation »

Tree tree object with data and subtrees

NestTree gives the tree of nesting a function

FileSystemTree gives the tree of subdirectories and files in a directory

RulesTree  ▪  ExpressionTree  ▪  GraphTree  ▪  RandomTree  ▪  ...

Visualization »

Tree automatic visualization for trees

TreeOutline create an outline view of a tree

TreeElementLabel  ▪  TreeElementStyle  ▪  TreeLayout

Properties and Measurements »

TreeData extract the data from a tree

TreeChildren extract the children from a tree

RootTree extract the root of a tree

TreeSize  ▪  TreeDepth  ▪  TreeLeaves  ▪  TreePosition  ▪  TreeExtract  ▪  ...

Computation on Trees »

NestTree recursively build up a tree by applying a function to the leaves

TreeFold recursively reduce a tree to a single value

TreeMap traverse a tree, applying a function to each subtree

TreeTraversalOrder specify the order to visit the nodes in a tree

TreeInsert  ▪  TreeDelete  ▪  TreeReplacePart  ▪  ...