Recall & Review
beginner Click to reveal answer
What does it mean for a binary tree to be balanced?
A binary tree is balanced if for every node, the height difference between its left and right subtrees is at most 1.
beginner Click to reveal answer
Why is checking the height difference important in a balanced binary tree?
Because a large height difference means one side is much deeper, causing inefficient operations like search or insert.
intermediate Click to reveal answer
What is the time complexity of a naive approach to check if a binary tree is balanced?
The naive approach has O(n²) time complexity because it calculates height for each node repeatedly.
intermediate Click to reveal answer
How can we optimize the check for a balanced binary tree?
By calculating height and balance status in the same recursion, returning -1 if unbalanced, achieving O(n) time complexity.
intermediate Click to reveal answer
What does a return value of -1 indicate in the optimized balanced tree check?
It indicates that the subtree is not balanced, so no need to check further.
What is the maximum allowed height difference between left and right subtrees for a balanced binary tree?
✗ Incorrect
A balanced binary tree allows a height difference of at most 1 between left and right subtrees.
Which approach is more efficient to check if a binary tree is balanced?
✗ Incorrect
Calculating height and balance in one recursion avoids repeated height calculations, making it efficient.
What does a height return value of -1 mean in the optimized check?
✗ Incorrect
Returning -1 signals that the subtree is not balanced.
What is the time complexity of the optimized balanced tree check?
✗ Incorrect
The optimized approach visits each node once, so time complexity is O(n).
If a node's left subtree height is 3 and right subtree height is 5, is the tree balanced at that node?
✗ Incorrect
Height difference is 2, which is more than 1, so the node is not balanced.
Explain how to check if a binary tree is balanced using a single recursive function.
Think about combining height calculation and balance check in one step.
You got /5 concepts.
Describe why the naive approach to check if a binary tree is balanced can be inefficient.
Consider how many times height is computed for each node.
You got /4 concepts.
