TreeDepth

TreeDepth[tree]

gives the maximum level of tree.

TreeDepth[tree,pattern]

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

Details

  • TreeDepth can give the maximum level of the subtree with data matching any pattern in a Tree object.
  • The depth of a tree is the maximum number of prior levels needed to reach the root from the leaves.
  • When counting the maximum level of a tree, empty lists of children contribute one level. »

Examples

open allclose all

Basic Examples  (1)

Find the depth of a tree:

Find the depth of an expression matching a pattern:

Properties & Relations  (6)

TreeDepth[tree] is generally equivalent to TreeDepth[tree,_]:

In TreeDepth[tree], empty lists of children contribute one level:

TreeDepth[Tree[{tree1,tree2,}]] gives 1+Max[TreeDepth[tree1],TreeDepth[tree2],]:

TreeDepth[Tree[data,None]] gives 0:

TreeDepth[Tree[data,{}]] gives 1:

TreeDepth can be computed using TreeFold:

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

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

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

Text

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

CMS

Wolfram Language. 2021. "TreeDepth." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. 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

BibTeX

@misc{reference.wolfram_2024_treedepth, author="Wolfram Research", title="{TreeDepth}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeDepth.html}", note=[Accessed: 03-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_treedepth, organization={Wolfram Research}, title={TreeDepth}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeDepth.html}, note=[Accessed: 03-November-2024 ]}