Recall & Review
beginner
What does the 'maximum width' of a binary tree mean?
The maximum width of a binary tree is the maximum over all levels of (index of rightmost node - index of leftmost node + 1).
Click to reveal answer
beginner
How can we track the width of each level in a binary tree?
We can track the width by recording the minimum and maximum indices of nodes at each level during a level-order traversal (breadth-first search).
Click to reveal answer
intermediate
Why do we assign indices to nodes when calculating maximum width?
Assigning indices to nodes helps to account for missing nodes between the leftmost and rightmost nodes at a level, ensuring the width includes gaps.
Click to reveal answer
beginner
What data structure is commonly used to implement the maximum width calculation?
A queue is used to perform a level-order traversal, storing nodes along with their indices to calculate width at each level.
Click to reveal answer
intermediate
Explain the formula to calculate width at a given level using node indices.
Width at a level = (index of rightmost node) - (index of leftmost node) + 1. This includes all nodes and gaps between them.
Click to reveal answer
What traversal method is used to find the maximum width of a binary tree?
✗ Incorrect
Level-order traversal visits nodes level by level, which is necessary to count nodes at each level for width calculation.
Why do we assign indices to nodes during traversal?
✗ Incorrect
Indices help measure the distance between leftmost and rightmost nodes, including gaps, to get the true width.
If the leftmost node at a level has index 4 and the rightmost node has index 7, what is the width of that level?
✗ Incorrect
Width = rightmost index - leftmost index + 1 = 7 - 4 + 1 = 4.
Which data structure is best suited to store nodes and their indices during traversal?
✗ Incorrect
A queue supports FIFO order needed for level-order traversal.
What is the maximum width of a tree with only one node?
✗ Incorrect
With one node, the maximum width is 1 because there is only one node at the root level.
Describe the steps to calculate the maximum width of a binary tree using level-order traversal and node indexing.
Think about how to visit nodes level by level and how to measure the distance between nodes.
You got /5 concepts.
Explain why simply counting nodes at each level might not give the correct maximum width in some binary trees.
Consider a tree where some nodes are missing in the middle of a level.
You got /4 concepts.