TreeMap

TreeMap[f,tree]

applies f to the data in each subtree of tree.

TreeMap[f,tree,levelspec]

applies f to the data on levels of tree specified by levelspec.

TreeMap[f,tree,levelspecelem]

applies f to the element elem of subtrees on levels specified by levelspec.

TreeMap[f]

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

Details

  • In TreeMap[f,tree], tree must be a TreeQ object.
  • TreeMap[f,tree,levelspec"Tree"] applies f to the subtree itself, rather than its data.
  • TreeMap[f,tree,levelspec"Data"] is equivalent to TreeMap[f,tree,levelspec].
  • TreeMap uses standard level specifications:
  • nlevels 1 through n
    Infinitylevels 1 through Infinity
    {n}level n only
    {n1,n2}levels n1 through n2
  • The default value for levelspec in TreeMap is {0,Infinity}.
  • 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.
  • TreeMap traverses subtrees in a left-to-right, depth-first order, with children visited before their parents.
  • TreeMap[f][tree] is equivalent to TreeMap[f,tree].

Examples

Basic Examples  (4)

Map f on the data of a tree:

Map f on the specified levels:

Map f on the subtrees of a tree:

Apply TreeMap as an operator form:

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

Text

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

BibTeX

@misc{reference.wolfram_2021_treemap, author="Wolfram Research", title="{TreeMap}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/TreeMap.html}", note=[Accessed: 22-June-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_treemap, organization={Wolfram Research}, title={TreeMap}, year={2021}, url={https://reference.wolfram.com/language/ref/TreeMap.html}, note=[Accessed: 22-June-2021 ]}

CMS

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

APA

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