Data Structure Questions and Answers-Inorder Traversal

Click on any option to know the CORRECT ANSWERS

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

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

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

Question 2 Explanation:
Level order traversal follows a breadth first search approach.

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

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

 Question 4
Select the code snippet which performs level-order traversal.
 A public static void levelOrder(Tree root) { Queue queue=new LinkedList(); queue.add(root); while(!queue.isEmpty( B public static void levelOrder(Tree root) { Queue queue=new LinkedList(); queue.add(root); while(! C public static void levelOrder(Tree root) { Queue queue=new LinkedList(); queue.add(root); while(!queue.isEmpty( D None of the mentioned
Economics Questions answers

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
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)
EVS Questions answers

Question 5 Explanation:
In the worst case we have d stack frames in the recursive call, hence the complexity is O(d).

There are 5 questions to complete.