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?
- A. 9 and 11
- B. 1 and 11
- C. 1 and 10
- 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.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Binary trees (unlabelled, left and right children distinguished) with exactly 6 nodes: how many have height exactly 3 (a single node has…
- Height is counted in edges (a single node has height 0). What is the maximum possible height of an AVL tree with 50 nodes, and what is the…
- How many distinct binary trees (left and right children are distinguished) on nodes 1..5 have preorder 1 2 3 4 5 and postorder 5 4 3 2 1?
- Among all binary trees (left and right children distinguished) with 6 nodes whose preorder traversal is 1 2 3 4 5 6, how many have an…
- A complete binary tree (every level full except possibly the last, which is filled from the left) has exactly 300 leaves. Which node…
- A rooted tree has 6 nodes with 2 children, 5 nodes with 3 children and 4 nodes with 4 children; every other node is a leaf. How many nodes…