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 allApplications (1)
Properties & Relations (8)
TreeLeafCount[tree] is equivalent to Length[TreeSelect[tree,TreeLeafQ]]:
TreeLeafCount[[image]]% === Length[TreeSelect[[image], TreeLeafQ]]TreeLeafCount[tree] is equivalent to Length[TreeLeaves[tree]]:
TreeLeafCount[[image]]% === Length[TreeLeaves[[image]]]TreeLeafCount[tree] is equivalent to TreeCount[tree,_,{-1}]:
TreeLeafCount[[image]]% === TreeCount[[image], _, {-1}]TreeLeafCount[Tree[{tree1,tree2,…}]] gives TreeLeafCount[tree1]+TreeLeafCount[tree2]+…:
TreeLeafCount[[image]]% === TreeLeafCount[[image]] + TreeLeafCount[[image]]TreeLeafCount[Tree[data,None]] gives 1:
TreeLeafCount[[image]]TreeLeafCount[Tree[data,{}]] gives 0:
TreeLeafCount[[image]]TreeSize[Tree[data,{}]] gives 1:
TreeSize[[image]]TreeLeafCount can be computed using TreeFold:
TreeLeafCount[[image]]% === TreeFold[{Total@#2&, 1&}, [image]]LeafCount[expr] is generally equivalent to TreeLeafCount[ExpressionTree[expr,"Subexpressions",HeadsTrue]]:
LeafCount[1[2[4[8, 9], 5[10]], 3[6, 7]]]ExpressionTree[1[2[4[8, 9], 5[10]], 3[6, 7]], "Subexpressions", Heads -> True]TreeLeafCount[%]LeafCount[expr,HeadsFalse] is generally equivalent to TreeLeafCount[ExpressionTree[expr,"Subexpressions"]]:
LeafCount[1[2[4[8, 9], 5[10]], 3[6, 7]], Heads -> False]ExpressionTree[1[2[4[8, 9], 5[10]], 3[6, 7]], "Subexpressions"]TreeLeafCount[%]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_2026_treeleafcount, author="Wolfram Research", title="{TreeLeafCount}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeLeafCount.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_treeleafcount, organization={Wolfram Research}, title={TreeLeafCount}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeLeafCount.html}, note=[Accessed: 15-June-2026]}