The height of a binary tree is the number of edges on the longest path from the root node to a leaf node. It measures how tall the tree is.
Click to reveal answer
beginner
How do you calculate the height of an empty binary tree?
The height of an empty binary tree is defined as -1 because there are no nodes and no edges.
Click to reveal answer
beginner
What is the height of a binary tree with only one node (the root)?
The height is 0 because there are no edges from the root to any leaf (the root itself is a leaf).
Click to reveal answer
intermediate
Explain the recursive approach to find the height of a binary tree.
To find the height, recursively find the height of the left subtree and the right subtree, then take the maximum of these two heights and add 1 for the current node.
Click to reveal answer
intermediate
Why do we add 1 when calculating the height recursively?
We add 1 to count the current node itself, moving one level down the tree.
Click to reveal answer
What is the height of a binary tree with only the root node?
A0
B1
C-1
D2
✗ Incorrect
A tree with only root has height 0 because there are no edges.
What is the height of an empty binary tree?
A1
B0
C-1
DUndefined
✗ Incorrect
By definition, an empty tree has height -1.
Which of these best describes how to find the height of a binary tree?
AFind the longest path from root to leaf in edges
BCount the number of leaf nodes
CCount the number of nodes
DFind the shortest path from root to leaf
✗ Incorrect
Height is the longest path from root to leaf measured in edges.
In the recursive height calculation, what do you do after finding left and right subtree heights?
AAdd them
BIgnore them
CTake the minimum
DTake the maximum and add 1
✗ Incorrect
We take the maximum height of the two subtrees and add 1 for the current node.
If a binary tree has height 3, how many edges are there on the longest path from root to leaf?
A2
B3
C4
D5
✗ Incorrect
Height counts edges, so height 3 means 3 edges on the longest path.
Describe how to find the height of a binary tree using recursion.
Think about how you break down the problem into smaller parts.
You got /4 concepts.
Explain why the height of an empty binary tree is defined as -1.
Consider what height means and how it relates to edges.
You got /4 concepts.
Practice
(1/5)
1. What is the height of a binary tree with only one node (the root)?
easy
A. 2
B. Undefined
C. 1
D. 0
Solution
Step 1: Understand height definition
The height of a binary tree is the number of edges on the longest path from the root to a leaf.
Step 2: Apply to single node tree
With only one node (root), the longest path has length 0 edges.
Final Answer:
0 -> Option D
Quick Check:
Single node tree height = 0 [OK]
Hint: Height counts edges on longest root-to-leaf path [OK]
Common Mistakes:
Thinking height is 0 for single node
Confusing height with number of nodes
Assuming height undefined for single node
2. Which of the following is the correct C++ function signature to calculate the height of a binary tree node named Node?
easy
A. int height(Node* root);
B. void height(Node root);
C. int height(Node root);
D. Node height(Node* root);
Solution
Step 1: Identify return type
The height function returns an integer representing height, so return type is int.
Step 2: Identify parameter type
Binary tree nodes are usually passed as pointers to avoid copying, so parameter is Node* root.
Final Answer:
int height(Node* root); -> Option A
Quick Check:
Return int, parameter Node pointer [OK]
Hint: Height returns int, takes pointer to Node [OK]
Common Mistakes:
Using void return type
Passing Node by value
Returning Node instead of int
3. What is the output of the following C++ code snippet?