TreeDepth

TreeDepth[tree]

gives the maximum level of tree.

TreeDepth[tree,pattern]

gives the maximal level of the subtree with data matching pattern.

Details

  • In TreeDepth[tree,pattern], tree must be a valid Tree object.
  • The depth of a tree is the maximum number of prior levels needed to reach the root from the leaves.
  • TreeDepth[tree] is equivalent to Max[Length/@TreePosition[tree,_]].

Examples

open allclose all

Basic Examples  (1)

Find the depth of a tree:

Find the depth of an expression matching a pattern:

Properties & Relations  (3)

TreeDepth[tree] gives the length of the longest position in tree:

Depth[expr] is equivalent to TreeDepth[ExpressionTree[expr,"Arguments"]]+1:

Depth[expr,HeadsTrue] is equivalent to TreeDepth[ExpressionTree[expr,"Subexpressions"]]+1:

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

Text

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

BibTeX

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

BibLaTeX

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

CMS

Wolfram Language. 2021. "TreeDepth." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TreeDepth.html.

APA

Wolfram Language. (2021). TreeDepth. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeDepth.html