Boundary Traversal means visiting the nodes on the outer edge 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 bottom-up 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 traversal step. The left and right boundary traversals exclude leaf nodes to avoid duplicates.
Click to reveal answer
beginner
What is the order of nodes printed in boundary traversal?
The order is:
Root node
Left boundary top-down (excluding leaves)
All leaf nodes left to right
Right boundary bottom-up (excluding leaves)
Click to reveal answer
beginner
Show a simple C function signature for boundary traversal of a binary tree.
void boundaryTraversal(struct Node* root); This function prints the boundary nodes of the binary tree starting from root.
Click to reveal answer
Which node is always the first printed in boundary traversal?
ARightmost leaf
BRoot node
CLeftmost leaf
DRight boundary node
✗ Incorrect
Boundary traversal always starts from the root node.
In boundary traversal, how are leaf nodes printed?
AOnly left leaves
BOnly right leaves
CLeaves are not printed
DAll leaves from left to right
✗ Incorrect
All leaf nodes are printed from left to right in boundary traversal.
How is the right boundary printed in boundary traversal?
ABottom-up excluding leaves
BTop-down including leaves
CLeft to right
DNot printed
✗ Incorrect
Right boundary nodes are printed in bottom-up order excluding leaf nodes.
Why do we exclude leaf nodes from left and right boundary traversals?
ATo avoid printing root twice
BLeaves are not part of boundary
CTo avoid printing leaves twice
DLeaves are printed only in right boundary
✗ Incorrect
Leaf nodes are printed once during leaf traversal, so excluding them from boundaries avoids duplicates.
Which traversal technique is NOT used in boundary traversal?
ALevel order
BInorder
CPostorder
DPreorder
✗ Incorrect
Boundary traversal does not use level order traversal.
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 a separate step.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the Boundary Traversal of Binary Tree?
easy
A. To print all nodes on the boundary of the tree in an anti-clockwise direction
B. To print all nodes in level order
C. To print all leaf nodes only
D. To print nodes in in-order traversal
Solution
Step 1: Understand boundary traversal definition
Boundary traversal prints nodes on the edges of the tree: left boundary, leaves, and right boundary.
Step 2: Compare with other traversals
Level order prints all nodes level-wise, leaf traversal prints only leaves, in-order prints nodes in left-root-right order.
Final Answer:
To print all nodes on the boundary of the tree in an anti-clockwise direction -> Option A
Hint: Traversal functions usually take pointer and return void [OK]
Common Mistakes:
Using struct keyword incorrectly
Passing node by value instead of pointer
Returning int instead of void
3. Consider the following binary tree:
1
/ \
2 3
/ \ \
4 5 6
/ \ / \
7 8 9 10
What is the output of the boundary traversal (anti-clockwise) of this tree?
medium
A. [1, 2, 4, 5, 7, 8, 9, 10, 6, 3]
B. [1, 2, 4, 7, 8, 9, 10, 3, 6]
C. [1, 2, 4, 7, 8, 9, 10, 6, 3]
D. [1, 2, 4, 7, 8, 5, 9, 10, 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, 10
Step 3: Identify right boundary nodes bottom-up excluding leaves
Right boundary: 6, 3
Step 4: Combine in anti-clockwise order
Boundary traversal: 1, 2, 4, 7, 8, 9, 10, 6, 3
Final Answer:
[1, 2, 4, 7, 8, 9, 10, 6, 3] -> Option C
Quick Check:
Left boundary + leaves + right boundary = [1, 2, 4, 7, 8, 9, 10, 6, 3] [OK]
Hint: Left boundary + leaves + right boundary in order [OK]
Common Mistakes:
Including leaf nodes twice in boundary
Wrong order of right boundary nodes
Missing some leaf nodes
4. The following C code snippet is intended to print the boundary traversal of a binary tree. What is the error?
void printLeftBoundary(Node* root) {
if (root == NULL) return;
printf("%d ", root->data);
if (root->left) {
printLeftBoundary(root->left);
} else if (root->right) {
printLeftBoundary(root->right);
}
}
medium
A. It does not print the root node
B. It prints leaf nodes which should be excluded in left boundary
C. It does not handle NULL root correctly
D. It prints nodes in bottom-up order instead of top-down
Solution
Step 1: Analyze printing condition in left boundary
Function prints node data before recursive call, so top-down order is correct.
Step 2: Check if leaf nodes are excluded
The printf is before the child checks, so leaf nodes are printed before returning.
Step 3: Identify error
Leaf nodes should not be printed in left boundary function; they are printed separately in leaf traversal.
Final Answer:
It prints leaf nodes which should be excluded in left boundary -> Option B
Quick Check:
Left boundary excludes leaves [OK]
Hint: Exclude leaf nodes in left boundary function [OK]
Common Mistakes:
Printing leaf nodes in left or right boundary functions
Not checking for NULL root
Printing nodes in wrong order
5. Given a binary tree where some nodes have only one child, how should the boundary traversal be adapted to correctly include all boundary nodes without duplicates? Choose the best approach.
hard
A. Traverse all nodes in level order and print only those with one child
B. Traverse left and right boundaries including leaves, then print all leaves
C. Print all nodes in in-order traversal and remove duplicates afterwards
D. Traverse left boundary top-down excluding leaves, then all leaves left to right, then right boundary bottom-up excluding leaves, skipping duplicates
Solution
Step 1: Understand boundary traversal with single-child nodes
Nodes with one child may appear in left or right boundary or as leaves.
Step 2: Avoid duplicates by excluding leaves in boundary traversals
Left and right boundary traversals exclude leaves to avoid duplicates; leaves are printed separately.
Step 3: Combine traversals carefully
Traverse left boundary top-down excluding leaves, then leaves left to right, then right boundary bottom-up excluding leaves, skipping duplicates.
Final Answer:
Traverse left boundary top-down excluding leaves, then all leaves left to right, then right boundary bottom-up excluding leaves, skipping duplicates -> Option D
Quick Check:
Exclude leaves in boundaries, print leaves separately [OK]
Hint: Exclude leaves in boundaries, print leaves separately [OK]
Common Mistakes:
Including leaves in both boundary and leaf traversals causing duplicates
Ignoring nodes with single child in boundary
Printing nodes in wrong order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.