Data Structure Questions and Answers-Preorder Traversal

 

 Buy/Download all MCQ Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Preorder Traversal

Click on any option to know the CORRECT ANSWERS

Question 1
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
Biology Questions answers

Question 1 Explanation: 
Pre order traversal follows NLR(Node-Left-Right).

Question 2
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
English grammar Questions answers

Question 2 Explanation: 
Post order traversal follows LRN(Left-Right-Node).

Question 3
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
UPSC Questions answers

Question 3 Explanation: 
Pre-order traversal follows NLR(Node-Left-Right).

Question 4
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
Microbiology Questions answers

Question 4 Explanation: 
Post order traversal follows NLR(Left-Right-Node).

Question 5
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

Management Questions answers

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.

 

 Buy/Download all MCQ Ebook >>>CLICK HERE<<<