Consider the following tree structure:
1
/ \
2 3
/ \
4 5
What is the depth of node 5?
Depth is how many edges from the root to the node.
Node 5 is two edges away from the root (1 -> 2 -> 5), so depth is 2.
Given the tree:
1
/ \
2 3
/ \
4 5
What is the height of node 2?
Height is the longest path from the node down to a leaf.
Node 2 has children 4 and 5 which are leaves (height 0), so height of node 2 is 1 + max(0,0) = 1. Since height counts edges, height is 1.
In the tree below, which node is a leaf?
10
/ \
5 15
/ \
3 20
7
A leaf node has no children.
Node 7 has no children, so it is a leaf. Nodes 5 and 15 have children, and 10 is the root.
Given the tree:
10
/ \
5 15
/ \
3 20
7
What is the level of node 20?
Level is depth + 1.
Node 20 is at depth 2 (edges: 10 -> 15 -> 20), so level = depth + 1 = 3.
Choose the correct statement about the root node in a tree.
Think about the position of the root in a tree.
The root node is the top node with no parent and depth 0. It can have children and is not a leaf.
