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.

Examples

open allclose all

Basic Examples  (4)

A tree with two leaves:

A tree with multiple levels:

A tree with data in the leaves:

A tree containing another tree as data:

Scope  (2)

Represent a leaf with no child:

Specify children in a list:

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:

Construct a Tree expression with GraphTree:

Wolfram Research (2021), Tree, Wolfram Language function, https://reference.wolfram.com/language/ref/Tree.html.

Text

Wolfram Research (2021), Tree, Wolfram Language function, https://reference.wolfram.com/language/ref/Tree.html.

BibTeX

@misc{reference.wolfram_2021_tree, author="Wolfram Research", title="{Tree}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/Tree.html}", note=[Accessed: 19-September-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_tree, organization={Wolfram Research}, title={Tree}, year={2021}, url={https://reference.wolfram.com/language/ref/Tree.html}, note=[Accessed: 19-September-2021 ]}

CMS

Wolfram Language. 2021. "Tree." Wolfram Language & System Documentation Center. Wolfram Research. 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