Recall & Review
beginner
What does the Top View of a binary tree represent?
The top view of a binary tree shows the nodes visible when the tree is seen from above. It includes the nodes that appear first at each horizontal distance from the root.
Click to reveal answer
beginner
How do we determine the horizontal distance (HD) of nodes in a binary tree?
The root node has HD = 0. For any node, its left child has HD = parent's HD - 1, and its right child has HD = parent's HD + 1.
Click to reveal answer
intermediate
Which data structure is commonly used to find the top view of a binary tree?
A queue is used for level order traversal, and a map (or dictionary) stores the first node encountered at each horizontal distance.
Click to reveal answer
intermediate
Why do we store only the first node at each horizontal distance when computing the top view?
Because the first node encountered at a horizontal distance during level order traversal is the topmost node visible from above at that horizontal distance.
Click to reveal answer
intermediate
What is the time complexity of finding the top view of a binary tree using level order traversal?
The time complexity is O(n), where n is the number of nodes, because each node is visited once.
Click to reveal answer
What is the horizontal distance of the root node in a binary tree?
✗ Incorrect
The root node is assigned a horizontal distance of 0 by definition.
Which traversal method is best suited to find the top view of a binary tree?
✗ Incorrect
Level order traversal visits nodes level by level, which helps identify the first node at each horizontal distance.
In the top view, if two nodes share the same horizontal distance, which one is included?
✗ Incorrect
The node at the higher (top) level is visible from above, so it is included in the top view.
What data structure helps track the first node at each horizontal distance?
✗ Incorrect
A map or dictionary stores horizontal distance as key and the first node's value as value.
What is the output of the top view for a single-node binary tree?
✗ Incorrect
With only one node, the top view is just that node.
Explain how to compute the top view of a binary tree step-by-step.
Think about how you see the tree from above and which nodes block others.
You got /5 concepts.
Describe why level order traversal is preferred over inorder or preorder for top view.
Consider which traversal visits nodes closest to the top first.
You got /4 concepts.