Data Structure Questions and Answers-Preorder Traversal

YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

CLICK HERE TO DOWNLOAD

Data Structure Questions and Answers-Preorder Traversal

Question 1 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
For the tree below, write the pre-order traversal.
A
2, 7, 2, 6, 5, 11, 5, 9, 4
B
2, 7, 5, 2, 6, 9, 5, 11, 4
C
2, 5, 11, 6, 7, 4, 9, 5, 2
D
2, 7, 5, 6, 11, 2, 5, 4, 9
Question 1 Explanation: 
Pre order traversal follows NLR(Node-Left-Right).

Question 2 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
For the tree below, write the post-order traversal.
A
2, 7, 2, 6, 5, 11, 5, 9, 4
B
2, 7, 5, 2, 6, 9, 5, 11, 4
C
2, 5, 11, 6, 7, 4, 9, 5, 2
D
2, 7, 5, 6, 11, 2, 5, 4, 9
Question 2 Explanation: 
Post order traversal follows LRN(Left-Right-Node).

Question 3 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Select the code snippet which performs pre-order traversal.
A

public void preorder(Tree root) { 	System.out.println(root.data); 	preorder(root.left); 	preorder(root.right); }
B

public void preorder(Tree root) { 	preorder(root.left); 	System.out.println(root.data); 	preorder(root.right); }
C

public void preorder(Tree root) { 	System.out.println(root.data); 	preorder(root.right); 	preorder(root.left); }
D
None of the mentioned
Question 3 Explanation: 
Pre-order traversal follows NLR(Node-Left-Right).

Question 4 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Select the code snippet which performs post-order traversal.
A

public void postorder(Tree root) { 	System.out.println(root.data); 	postorder(root.left); 	postorder(root.right); }
B

public void postorder(Tree root) { 	postorder(root.left); 	postorder(root.right); 	System.out.println(root.data); }
C

public void postorder(Tree root) { 	System.out.println(root.data); 	postorder(root.right); 	postorder(root.left); }
D
None of the mentioned
Question 4 Explanation: 
Post order traversal follows NLR(Left-Right-Node).

Question 5 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Select the code snippet that performs pre-order traversal iteratively.
A

public void preOrder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); st.add<
B

public void preOrder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); while (!stk.
C

public void preOrder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); st.add(root)
D
None of the mentioned

Question 5 Explanation: 
Add the root to the stack first, then continously check for the right and left children of the top-of-the-stack.

There are 5 questions to complete.