Boundary Traversal means visiting the nodes on the boundary of the tree in an anti-clockwise direction starting from the root. It includes the left boundary, leaves, and right boundary.
Click to reveal answer
beginner
Which parts of the binary tree are included in the boundary traversal?
The boundary traversal includes three parts:
Left boundary (excluding leaves)
All leaf nodes (left to right)
Right boundary (excluding leaves, in reverse order)
Click to reveal answer
intermediate
How do you avoid printing leaf nodes twice in boundary traversal?
Leaf nodes are printed only once during the leaf nodes traversal step. Left and right boundaries exclude leaf nodes to avoid duplicates.
Click to reveal answer
beginner
What is the order of traversal in boundary traversal of a binary tree?
The order is: 1. Root node 2. Left boundary top-down (excluding leaves) 3. Leaf nodes left to right 4. Right boundary bottom-up (excluding leaves)
Click to reveal answer
beginner
Show the C# method signature for boundary traversal of a binary tree.
public List<int> BoundaryTraversal(TreeNode root)<br><br>Where TreeNode is a class with int val, TreeNode left, and TreeNode right.
Click to reveal answer
Which nodes are NOT included in the left boundary during boundary traversal?
AAll nodes
BRoot node
CRight child nodes
DLeaf nodes
✗ Incorrect
Leaf nodes are excluded from the left boundary to avoid duplication since they are printed separately.
In which order are the right boundary nodes printed in boundary traversal?
ATop to bottom
BBottom to top
CLeft to right
DRandom order
✗ Incorrect
Right boundary nodes are printed from bottom to top to maintain anti-clockwise order.
What is the first node printed in boundary traversal?
ALeftmost leaf
BRightmost leaf
CRoot node
DRight boundary node
✗ Incorrect
The traversal starts from the root node.
Which traversal is used to print leaf nodes in boundary traversal?
AAny traversal that visits all leaves left to right
BInorder
CPostorder
DPreorder
✗ Incorrect
Leaf nodes are printed in left to right order, so any traversal visiting leaves in that order works.
If a tree has only root node, what is the boundary traversal output?
ARoot node value only
BEmpty
CLeft boundary only
DRight boundary only
✗ Incorrect
With only root node, boundary traversal prints just the root.
Explain the steps to perform boundary traversal of a binary tree.
Think about the three parts of the boundary and their order.
You got /4 concepts.
How do you handle leaf nodes to avoid duplicates in boundary traversal?
Leaves appear in both boundary and leaf sets.
You got /3 concepts.
Practice
(1/5)
1. What does the Boundary Traversal of a binary tree include?
easy
A. Only the root node
B. Left boundary, leaves, and right boundary nodes in order
C. All nodes in level order
D. Only the leaf nodes of the tree
Solution
Step 1: Understand boundary traversal components
Boundary traversal includes nodes on the left edge, all leaf nodes, and nodes on the right edge.
Step 2: Combine these parts in order
Traverse left boundary top-down, then leaves left to right, then right boundary bottom-up.
Final Answer:
Left boundary, leaves, and right boundary nodes in order -> Option B
Quick Check:
Boundary traversal = left + leaves + right [OK]
Hint: Remember: left edge, leaves, right edge in sequence [OK]
Common Mistakes:
Including root multiple times
Missing leaf nodes
Reversing right boundary order
2. Which of the following C# method signatures is correct for a function that performs boundary traversal on a binary tree node root and returns a list of integers?
easy
A. public void BoundaryTraversal(int root)
B. public int BoundaryTraversal(Node root)
C. public List<int> BoundaryTraversal(Node root)
D. public List BoundaryTraversal(Node root)
Solution
Step 1: Check return type and parameter
Boundary traversal returns a list of node values, so return type should be List<int> and parameter should be Node.
Step 2: Validate method signature syntax
public List<int> BoundaryTraversal(Node root) matches correct syntax: public List<int> BoundaryTraversal(Node root)
Final Answer:
public List<int> BoundaryTraversal(Node root) -> Option C
Quick Check:
Return list<int> and input Node root [OK]
Hint: Return list of ints, input is Node root [OK]
Common Mistakes:
Using void return type
Wrong parameter type (int instead of Node)
Missing generic type in List
3. Given the following binary tree:
1
/ \
2 3
/ \ \
4 5 6
/ \ /
7 8 9
What is the boundary traversal output?
medium
A. [1, 2, 4, 7, 8, 9, 3, 6]
B. [1, 2, 4, 7, 8, 9, 6]
C. [1, 2, 4, 7, 8, 9, 6, 3]
D. [1, 2, 4, 5, 7, 8, 9, 6, 3]
Solution
Step 1: Identify left boundary nodes
Left boundary (excluding leaves): 1, 2
Step 2: Identify leaf nodes left to right
Leaves: 4, 7, 8, 9
Step 3: Identify right boundary nodes bottom-up
Right boundary (excluding leaves): 3, 6
Step 4: Combine nodes without duplicates
Boundary traversal: 1, 2, 4, 7, 8, 9, 3, 6
Final Answer:
[1, 2, 4, 7, 8, 9, 3, 6] -> Option A
Quick Check:
Left + leaves + right = [1,2,4,7,8,9,3,6] [OK]
Hint: Left edge + leaves + right edge reversed [OK]
Common Mistakes:
Including leaf nodes twice
Missing right boundary node 3
Wrong order of leaves
4. Consider this C# code snippet for boundary traversal:
void PrintLeftBoundary(Node node) {
if (node == null) return;
Console.Write(node.Data + " ");
if (node.Left != null) {
PrintLeftBoundary(node.Left);
} else if (node.Right != null) {
PrintLeftBoundary(node.Right);
}
}
What is the bug in this code?
medium
A. It skips left boundary nodes
B. It does not print the root node
C. It causes infinite recursion on leaf nodes
D. It prints leaf nodes which should be excluded
Solution
Step 1: Analyze leaf node printing
The code prints node data before recursive call even if node is leaf, so leaf nodes get printed here.
Step 2: Understand boundary traversal rules
Left boundary function should exclude leaf nodes to avoid duplicates in leaf printing step.
Final Answer:
It prints leaf nodes which should be excluded -> Option D
Quick Check:
Left boundary excludes leaves [OK]
Hint: Exclude leaves in left boundary print [OK]
Common Mistakes:
Printing leaves in left boundary
Not checking for null nodes
Confusing left and right child checks
5. You want to perform boundary traversal on a binary tree but avoid printing duplicate nodes when the tree has only one node or skewed structure. Which approach is best?
hard
A. Print root, then left boundary excluding leaves, then leaves excluding root, then right boundary excluding leaves and root
B. Print all nodes in preorder traversal
C. Print leaves only once and ignore boundaries
D. Print left boundary including leaves, then right boundary including leaves
Solution
Step 1: Avoid duplicates by excluding leaves in boundaries
Exclude leaves from left and right boundary to prevent duplicates with leaf traversal.
Step 2: Handle root separately
Print root once at start, exclude it from right boundary to avoid repetition.
Step 3: Combine all parts carefully
Print root, left boundary (no leaves), leaves (excluding root), right boundary (no leaves or root) for correct order and no duplicates.
Final Answer:
Print root, then left boundary excluding leaves, then leaves excluding root, then right boundary excluding leaves and root -> Option A
Quick Check:
Exclude duplicates by careful boundary and leaf separation [OK]
Hint: Exclude leaves in boundaries, print root once [OK]
Common Mistakes:
Printing root multiple times
Including leaves in boundaries causing duplicates
Ignoring skewed tree edge cases
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.