applies f to the data in each subtree of tree.


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


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


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


  • 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].


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,


Wolfram Research (2021), TreeMap, Wolfram Language function,


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


@online{reference.wolfram_2021_treemap, organization={Wolfram Research}, title={TreeMap}, year={2021}, url={}, note=[Accessed: 22-June-2021 ]}


Wolfram Language. 2021. "TreeMap." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2021). TreeMap. Wolfram Language & System Documentation Center. Retrieved from