TreeLeafQ

TreeLeafQ[tree]

gives True if tree is a Tree object with no children, and gives False otherwise.

Details

Examples

open allclose all

Basic Examples  (1)

Test whether a tree is a leaf:

Scope  (1)

TreeLeafQ works for any expression:

Properties & Relations  (8)

In TreeLeafQ[tree], the tree must be a valid Tree object:

TreeLeafQ[Tree[data,None]] gives True:

TreeLeafQ[Tree[data,{subtree1,subtree2,}]] gives False:

TreeLeafQ[Tree[data,{}]] even gives False:

TreeLeafQ[tree] gives True when TreeChildren[tree] gives None:

TreeLeafQ[tree] gives False when TreeChildren[tree] gives a list:

TreeLeafQ[tree] gives False even when TreeChildren[tree] gives {}:

TreeLeafQ[tree] gives True when TreeDepth[tree] gives 0:

A root with an empty list of children has depth 1:

TreeSize[tree] gives 1 when TreeLeafQ[tree] gives True:

A root with an empty list of children also has size 1:

TreeLeaves[tree] returns the list of subtrees for which TreeLeafQ gives True:

TreeLeafCount[tree] is equivalent to Length[TreeSelect[tree,TreeLeafQ]]:

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

Text

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

CMS

Wolfram Language. 2021. "TreeLeafQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/TreeLeafQ.html.

APA

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

BibTeX

@misc{reference.wolfram_2024_treeleafq, author="Wolfram Research", title="{TreeLeafQ}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeLeafQ.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

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