TreeLevel

TreeLevel[tree,levelspec]

gives a list of all subtrees of tree on levels specified by levelspec.

TreeLevel[levelspec]

represents an operator form of TreeLevel that can be applied to a tree.

Details

  • In TreeLevel[tree,levelspec], tree must be a valid Tree object.
  • TreeLevel uses standard level specifications:
  • nlevels 1 through n
    Infinitylevels 1 through Infinity
    {n}level n only
    {n1,n2}levels n1 through n2
  • A positive level n+1 consists of all subtrees of tree that are children of subtrees on level n.
  • Level 0 corresponds to the root of the tree.
  • Level -1 corresponds to the leaves.
  • A negative level -(n+1) consists of all subtrees whose children are on levels -1, -2, , -n, with highest level -n.
  • TreeLevel traverses subtrees in a left-to-right, depth-first order, with children visited before their parents.

Examples

open allclose all

Basic Examples  (2)

Extract the subtrees on the second level:

Use the operator form of TreeLevel:

Scope  (3)

Extract the subtrees on levels 1, 2 and 3:

Extract all inner subtrees:

Use TreeLevel as an operator form in a tree position specification:

Applications  (2)

Extract subtrees at successive levels from the root:

Extract subtrees at successive levels from the bottom:

Properties & Relations  (3)

TreeLevel[tree,levelspec] is equivalent to TreeExtract[tree,TreeLevel[levelspec]]:

Level[expr,levelspec] is equivalent to TreeData[ExpressionTree[expr,"Arguments"],TreeLevel[levelspec]]:

Level[expr,levelspec,HeadsTrue] is equivalent to TreeData[ExpressionTree[expr,"Subexpressions"],TreeLevel[levelspec]] for positive levels:

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

Text

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

BibTeX

@misc{reference.wolfram_2021_treelevel, author="Wolfram Research", title="{TreeLevel}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/TreeLevel.html}", note=[Accessed: 27-November-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_treelevel, organization={Wolfram Research}, title={TreeLevel}, year={2021}, url={https://reference.wolfram.com/language/ref/TreeLevel.html}, note=[Accessed: 27-November-2021 ]}

CMS

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

APA

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