Consider a tree where the root node is at depth 0. What is the depth of a node that is three edges away from the root?
Depth counts the number of edges from the root to the node.
The depth of a node is the number of edges from the root to that node. If a node is three edges away, its depth is 3.
In a tree, what is the height of a leaf node?
Height is the number of edges on the longest path from the node down to a leaf.
A leaf node has no children, so the longest path down from it is zero edges. Therefore, its height is 0.
Given a tree where the root has three children with heights 2, 3, and 1 respectively, what is the height of the tree?
The height of a node is 1 plus the maximum height among its children.
The root's height is 1 plus the maximum height of its children. Max child height is 3, so root height = 1 + 3 = 4. However, the question asks for the height of the tree, which is the height of the root node. So the correct answer is 4.
Which statement correctly describes the difference between height and depth of a node in a tree?
Think about the direction each measure counts edges.
Depth measures distance from the root down to the node. Height measures distance from the node down to the farthest leaf. They are different concepts.
In a tree, the depths of all leaf nodes are 2, 3, 3, and 4. What is the height of the tree?
The height of the tree equals the maximum depth among all leaves.
The height of the tree is the length of the longest path from the root to any leaf. Since the deepest leaf is at depth 4, the tree height is 4.