TreeLeafCount

TreeLeafCount[tree]

gives the number of leaves of tree.

Details

Examples

open allclose all

Basic Examples  (1)

Count the leaves in a tree:

Applications  (1)

Randomly generated trees with n nodes have n/2 leaves on average:

Properties & 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"]]:

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

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_2024_treeleafcount, author="Wolfram Research", title="{TreeLeafCount}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeLeafCount.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_treeleafcount, organization={Wolfram Research}, title={TreeLeafCount}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeLeafCount.html}, note=[Accessed: 21-November-2024 ]}