WOLFRAM

TreeSize[tree]

gives the number of subtrees of tree.

Details

  • The number of subtrees of a Tree object is also the number of its nodes because each node is the root of a subtree of the original tree.
  • TreeSize[tree] is equivalent to TreeCount[tree,_].

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Count the subtrees in a tree:

Out[2]=2

Properties & Relations  (4)Properties of the function, and connections to other functions

TreeSize[tree] is equivalent to TreeCount[tree,_]:

Out[5]=5
Out[6]=6

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

Out[1]=1
Out[2]=2

TreeSize[Tree[data,None]] gives 1:

Out[1]=1

TreeSize[Tree[data,{}]] also gives 1:

Out[2]=2

TreeLeafCount[Tree[data,{}]] gives 0:

Out[3]=3

TreeSize can be computed using TreeFold:

Out[1]=1
Out[2]=2
Wolfram Research (2021), TreeSize, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeSize.html.
Wolfram Research (2021), TreeSize, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeSize.html.

Text

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

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

CMS

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

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

APA

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

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

BibTeX

@misc{reference.wolfram_2025_treesize, author="Wolfram Research", title="{TreeSize}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/TreeSize.html}", note=[Accessed: 26-March-2025 ]}

@misc{reference.wolfram_2025_treesize, author="Wolfram Research", title="{TreeSize}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/TreeSize.html}", note=[Accessed: 26-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_treesize, organization={Wolfram Research}, title={TreeSize}, year={2021}, url={https://reference.wolfram.com/language/ref/TreeSize.html}, note=[Accessed: 26-March-2025 ]}

@online{reference.wolfram_2025_treesize, organization={Wolfram Research}, title={TreeSize}, year={2021}, url={https://reference.wolfram.com/language/ref/TreeSize.html}, note=[Accessed: 26-March-2025 ]}