GATE Computer ScienceHardGATE CS (PYQ pattern)

A full binary tree (every node has 0 or 2 children) has preorder 1 2 4 5 8 9 3 6 10 11 7 and postorder 4 8 9 5 2 10 11 6 7 3 1. What are the 6th and 9th nodes of its inorder traversal?

  1. A. 9 and 11
  2. B. 1 and 11
  3. C. 1 and 10
  4. D. 1 and 3

Correct answer: B. 1 and 11

In a full binary tree pre- and postorder fix the tree: after root 1, preorder's next node 2 is the left child; 2 is the last node of its subtree in postorder, so the left subtree is {4, 8, 9, 5, 2} and the right subtree is the rest, rooted at 3. Recursing: 2 has children 4 and 5 (5 with 8, 9); 3 has children 6 (with 10, 11) and 7. Inorder: 4 2 8 5 9 1 10 6 11 3 7; the 6th is 1 and the 9th is 11.

More Programming and Data Structures (GATE) questions

Exams that ask this topic