TreeLeafCount[tree]
gives the number of leaves of tree.


TreeLeafCount
TreeLeafCount[tree]
gives the number of leaves of tree.
Details

- TreeLeafCount counts the number of leaves of a Tree object.
- TreeLeafCount[tree] is equivalent to TreeCount[tree,_,{-1}].
Examples
open all close allProperties & Relations (8)
TreeLeafCount[tree] is equivalent to Length[TreeSelect[tree,TreeLeafQ]]:
TreeLeafCount[tree] is equivalent to Length[TreeLeaves[tree]]:
TreeLeafCount[tree] is equivalent to TreeCount[tree,_,{-1}]:
TreeLeafCount[Tree[{tree1,tree2,…}]] gives TreeLeafCount[tree1]+TreeLeafCount[tree2]+…:
TreeLeafCount[Tree[data,None]] gives 1:
TreeLeafCount[Tree[data,{}]] gives 0:
TreeSize[Tree[data,{}]] gives 1:
TreeLeafCount can be computed using TreeFold:
LeafCount[expr] is generally equivalent to TreeLeafCount[ExpressionTree[expr,"Subexpressions",HeadsTrue]]:
LeafCount[expr,HeadsFalse] is generally equivalent to TreeLeafCount[ExpressionTree[expr,"Subexpressions"]]:
Related Guides
History
Text
Wolfram Research (2022), TreeLeafCount, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeLeafCount.html.
CMS
Wolfram Language. 2022. "TreeLeafCount." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TreeLeafCount.html.
APA
Wolfram Language. (2022). TreeLeafCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeLeafCount.html
BibTeX
@misc{reference.wolfram_2025_treeleafcount, author="Wolfram Research", title="{TreeLeafCount}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeLeafCount.html}", note=[Accessed: 15-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_treeleafcount, organization={Wolfram Research}, title={TreeLeafCount}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeLeafCount.html}, note=[Accessed: 15-August-2025]}