Tree Traversal MCQ Quiz - Objective Question with Answer for Tree Traversal - Download Free PDF
Last updated on Apr 22, 2025
Latest Tree Traversal MCQ Objective Questions
Tree Traversal Question 1:
Arrange the following steps of the Inorder Traversal of Binary Tree in the correct order.
A. Visit the Left subtree
B. Visit the Root node
C. Visit the Right subtree
D. Start traversing by visiting the nodes in rooted tree
E. Repeat the above three steps.
Choose the correct answer from the options given below:
Answer (Detailed Solution Below)
Tree Traversal Question 1 Detailed Solution
The correct answer is option 3: D, A, B, C, E
Key Points
Inorder traversal of a binary tree is a type of depth-first traversal where nodes are visited in the following order:
- Step 1: Start traversing by visiting the nodes in the rooted tree.
- Step 2: Visit the Left subtree.
- Step 3: Visit the Root node.
- Step 4: Visit the Right subtree.
- Step 5: Repeat the above three steps for each subtree.
Tree Traversal Question 2:
Considering above binary tree, what will be the inorder traversal
Answer (Detailed Solution Below)
Tree Traversal Question 2 Detailed Solution
The correct answer is 1) B A D C E G F H.
Key Points
- Inorder traversal of a binary tree visits nodes in the following order: left subtree, root node, right subtree.
- The provided sequence B A D C E G F H follows this rule, visiting the leftmost nodes first, then the root, and finally the rightmost nodes.
Additional Information
- Inorder traversal is used to get nodes of a binary search tree (BST) in non-decreasing order.
- This traversal method is used in many tree-related algorithms and problems.
- It is also useful in scenarios where the order of node processing matters, such as expression trees for arithmetic operations.
Tree Traversal Question 3:
The post-order traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, 3, 1. The inorder traversal of the same tree is 8, 6, 9, 4, 7, 2, 5, 1, 3. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is
Answer (Detailed Solution Below)
Tree Traversal Question 3 Detailed Solution
The correct answer is 4
Explanation:
To determine the height of the binary tree, we need to reconstruct the tree using the given post-order and in-order traversals and then calculate its height.
- Post-order traversal (left, right, root): Given as 8, 9, 6, 7, 4, 5, 2, 3, 1. The last element (1) is the root of the tree.
- In-order traversal (left, root, right): Given as 8, 6, 9, 4, 7, 2, 5, 1, 3. Locate the root (1), and split the in-order sequence into the left and right subtrees:
- Left subtree (elements before 1): 8, 6, 9, 4, 7, 2, 5
- Right subtree (elements after 1): 3
- Repeat the process for each subtree:
- Use post-order to identify the roots of the left and right subtrees.
- Use in-order to split into further left and right subtrees recursively.
Reconstructing the Binary Tree:
Longest path has length 4.
Tree Traversal Question 4:
Given the following expression tree, identify the correct arithmetic expression:
Answer (Detailed Solution Below)
Tree Traversal Question 4 Detailed Solution
Concept:
Algorithm:
Step 1: Put operands into stack when we visiting operator last time go to step 2
Step 2: Calculate pop1 operator pop2 and again push into stack and Repeat Step 1
Step 3: Repeat Step 1 and Step 2 until Root node is visited last time
Explanation:
So option 5 is the correct answer.
Tree Traversal Question 5:
______ pairs of traversals is not sufficient to build a unique binary tree.
Answer (Detailed Solution Below)
Tree Traversal Question 5 Detailed Solution
The correct answer is Postorder and Preorder.
Key Points
- Postorder and Preorder traversals are not sufficient to build a unique binary tree.
- To uniquely construct a binary tree, you generally need the Inorder traversal paired with either Preorder or Postorder traversal.
- Inorder traversal provides information about the relative positioning of nodes, which is crucial in tree reconstruction.
- Without Inorder traversal, multiple binary trees can yield the same Postorder and Preorder traversals, making it impossible to determine a unique structure.
Additional Information
- Inorder traversal is essential because it provides the relative positions of nodes in the tree, which cannot be derived from Preorder and Postorder traversals alone.
- Preorder traversal lists nodes in the order of root, left subtree, and right subtree.
- Postorder traversal lists nodes in the order of left subtree, right subtree, and root.
- Example:
- Consider a tree with nodes arranged such that multiple structures yield the same Preorder and Postorder traversals but differ in their Inorder traversal.
- Without Inorder traversal, these different structures cannot be distinguished.
Top Tree Traversal MCQ Objective Questions
The pre-order traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19.
Which one of the following is the post order traversal of the tree?Answer (Detailed Solution Below)
Tree Traversal Question 6 Detailed Solution
Download Solution PDFConcept:
A binary tree can be traversed in three ways:
- Preorder = (Root, Left subtree, Right Subtree)
- Inorder = (Left subtree, Root, Right Subtree)
- Postorder = (Left Subtree, Right subtree, Root)
Explanation:
In case of Binary Search Trees (BST), inorder traversal always sorts the tree nodes into ascending order.
Inorder traversal is 10, 11, 12, 15, 16, 18, 19, 20
Pre-order traversal is 15, 10, 12, 11, 20, 18, 16, 19.
In preorder traversal, the first node would be tree root and values less than root would be part of left
subtree and values greater than root node would form right subtree. So the resultant BST is:
Required Binary Search Tree:
Consider a complete binary tree with 7 nodes. Let A denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.
The value of |A - B| is _______
Answer (Detailed Solution Below) 1
Tree Traversal Question 7 Detailed Solution
Download Solution PDFAnswer: 1 to 1
Explanation:
Consider the following Complete Binary Tree
A - {A, B, C}
B - {A, B, D}
Set A contains the first 3 elements obtained while Performing BFS.
Set B contains the first 3 elements obtained while performing DFS.
B={A, B, D} ( with DFS multiple Sequences are possible you can select anyone Answer to this Question will be same for all those sequences).
| A - B |
=|{ A, B, C } – { A, B, D }|
=|{C}| = 1
What is the in-order successor of 15 in the given binary search tree?
Answer (Detailed Solution Below)
Tree Traversal Question 8 Detailed Solution
Download Solution PDFConcept –
The in-order sequence can be found following the chronology of Left-> Root-> Right.
Finding the in-order traversal sequence, we get 2, 3, 4, 6, 7, 9, 13, 15, 17, 18, 20.
The element that comes after 15 is its successor. It can be seen that 15’s successor is 17.
Explanation –
- In-order successor of a node is the minimum element in right subtree of the node in consideration.
- Here, in the right subtree of 15, 17 is the element with minimum value. Hence, 17 is 15’s in-order successor.
- Similarly, for finding the in-order predecessor of a node, the element with maximum value in left sub-tree is the answer. Here, 13 is 15’s in-order predecessor.
portant Point:
Tricks works only when the tree is Binary Search Tree.
What is the sequence of nodes when applying in-order traversal on the binary tree given below?
Answer (Detailed Solution Below)
Tree Traversal Question 9 Detailed Solution
Download Solution PDFConcept:
- In-order Traversal: Left -> Root -> Right
- Pre-order Traversal: Root -> Left -> Right
- Post-order Traversal : Left -> Right -> Root
Binary tree:
Inorder Traversal: A, B, C, D, E, F, G, H, I
The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,1. The inorder traversal of the same tree is 8,6,9,4,7,2,5,1,3. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is ______.
Answer (Detailed Solution Below) 4
Tree Traversal Question 10 Detailed Solution
Download Solution PDFLongest path has length 4.
When we perform in order traversal on a binary tree, we get the ascending order array. The tree is:
Answer (Detailed Solution Below)
Tree Traversal Question 11 Detailed Solution
Download Solution PDFOpttion 3: correct:
When we perform in order traversal on a binary tree, we get the ascending order array. The tree is binary search tree
Random binary search tree
Post-order traversal is 23, 18, 27, 25, 10, 60, 80, 70, 30.
In-order traversal traversal is 10, 18, 23, 25, 27, 30, 60, 70, 80
Preorder traversal is 30, 10, 25, 18, 23, 27, 70, 60 ,80
In order traversal, of the binary search tree is in ascending order.
If BDAECF and ABDCEF are inorder and preorder traversals of a binary tree (T) respectively, then post-order traversal of T is:
Answer (Detailed Solution Below)
Tree Traversal Question 12 Detailed Solution
Download Solution PDFData
In order is BDAECF
Preorder is ABDCEF
Binary tree
Therefore Post order will be DBEFCA
Consider the following statements.
S1 : The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2 : The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
Answer (Detailed Solution Below)
Tree Traversal Question 13 Detailed Solution
Download Solution PDFAnswer: Option 1
Explanation:
Statement 1:The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
Consider following example
Fun( int n )
{
if( n==0 || n==1)
return n;
else {
return Fun(n/2) + Fun(n/2) ;
}
Suppose function call made as Fun(8). now recursion tree will be
The Function call sequence will be (in terms of n): 8, 4, 2, 1, 1, 2, 1, 1, 4, 2, 1, 1, 2, 1, 1 ( Same as pre-order traversal of the tree )
The Function Returning Sequence will be : 1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8 ( Same as post-order traversal of the tree)
Hence This Statement is correct.
Statement 2:
This Statement is also correct.
Consider the following Inorder and Preorder traversal of a tree
Inorder – D B E F A G H C
Preorder - A B D E F C G H
What is the Postorder Traversal of the same tree
Answer (Detailed Solution Below)
Tree Traversal Question 14 Detailed Solution
Download Solution PDFConcept:
- Inorder and Preorder = Unique Binary tree
- Inorder and Postorder = Unique Binary tree
- Preorder and Postorder = More than one Binary tree
- Inorder Traversal: Left -> Root -> Right
- Preorder Traversal: Root -> Left -> Right
- Post Order Traversal : Left -> Right -> Root
Algorithm: (For Inorder and Preorder to make Binary tree)
Step 1: Pick a node in the same sequence in the Preorder
Step 2: Make left and right of picked node from Inorder
Step 3: Repeat Step 1
Step 4: Repeat Step 2, Loop till the last element in pre order
Explanation:
Binary tree after using this algorithm on pre order and in order:
Final Binary tree
Using Concept left-> right -> root for post order
Post order = D F E B H G C A
Hence option 3 is the correct answer.
For the following binary tree, inorder traversal yields the expression:
Answer (Detailed Solution Below)
Tree Traversal Question 15 Detailed Solution
Download Solution PDFConcept:
In the in-order traversal method, the left subtree is visited first, then the root and then the right subtree. Every node is a subtree in itself.
Explanation:
Given a binary tree :
For this, we first visit the left - subtree of root -.
1) It will first print a. Then root, + (a + )
2) Then it will go to right subtree, in this again left subtree of root *. It prints b , then * , then d (a + b * d)
3) Then it print "-". (a + b * d -)
4) Then move to right subtree. First print e, then /, then f .(e/f)
5) Final output will be : a + b * d - e/f