Data Structure Questions and Answers-Inorder Traversal

Data Structure Questions and Answers-Inorder Traversal

Congratulations - you have completed Data Structure Questions and Answers-Inorder Traversal.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%


Your answers are highlighted below.
Question 1 [CLICK ON ANY COICE TO KNOW RIGHT ANSWER]
For the tree below, write the in-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: 
In-order traversal follows LNR(Left-Node-Right).

Question 2 [CLICK ON ANY COICE TO KNOW RIGHT ANSWER]
For the tree below, write the level-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: 
Level order traversal follows a breadth first search approach.

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

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

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

public void inorder(Tree root) { 	System.out.println(root.data); 	inorder(root.right); 	inorder(root.left); }
D
None of the mentioned

Question 3 Explanation: 
In-order traversal follows LNR(Left-Node-Right).

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

public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!queue.isEmpty(
B

public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!
C

public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!queue.isEmpty(
D
None of the mentioned
Question 4 Explanation: 
Firstly add the root node to the queue. Then for all the remaining nodes, pop the front end of the queue and print it, add the left and right children of the popped node to the queue.

Question 5 [CLICK ON ANY COICE TO KNOW RIGHT ANSWER]
What is the space complexity of the in-order traversal in the recursive fashion? (d is the tree depth and n is the number of nodes)
A
O(1)
B
O(nlogd)
C
O(logd)
D
O(d)
Question 5 Explanation: 
In the worst case we have d stack frames in the recursive call, hence the complexity is O(d).

Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 5 questions to complete.