In a tree data structure, what is a leaf?
Options
- The top node
- A node with no children (Correct option)
- Any node with two children
- The connection between nodes
Answer
A node with no children
Why
A tree is made of nodes connected parent → child, with no cycles.
- Root: the single top node (no parent).
- Children: nodes directly below a node.
- Leaf: a node with no children.
- Height: number of levels from root to the deepest leaf.
Examples: folders on a disk, the HTML DOM, company org charts.
Remember
Root at the top, leaves at the bottom (no children).