# 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:
•  n levels 1 through n Infinity levels 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: