GATE Computer ScienceModerateGATE CS (PYQ pattern)
The preorder and inorder traversals of a binary tree are 7 3 1 2 5 4 6 and 1 3 2 7 4 5 6 respectively. What is its postorder traversal?
- A. 1 3 2 4 6 5 7
- B. 1 2 3 6 4 5 7
- C. 1 2 3 4 6 5 7
- D. 2 1 3 4 5 6 7
Correct answer: C. 1 2 3 4 6 5 7
Root 7; inorder left part 1 3 2 gives subtree rooted at 3 (children 1 and 2), the right part 4 5 6 rooted at 5 (children 4 and 6). Postorder: 1 2 3 4 6 5 7.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int a[] = {2, 4, 6, 8, 10}; int p = a + 1, q = a + 4; printf("%d %d %d", p + q, (q - 2), q - p); What is printed?
- int f(void) { static int c = 0; return ++c; } int main() { int x = f() || f(); int y = f() && f() > 3 ? f() : -f(); printf("%d %d %d", x…
- In a min-heap stored 1-indexed in an array with children of i at 2i and 2i+1, a node at index 77 is replaced by a smaller key and sifted…
- int a[] = {5, 3, 8, 4, 2, 9, 1, 7, 6, 10}; int st[10], top = -1, nge[10]; for (int i = 0; i < 10; i++) nge[i] = -1; for (int i = 0; i <…
- A min-stack keeps an auxiliary stack: a value is pushed on it when it is less than or equal to the current auxiliary top (or it is empty)…
- for (i = 1; i < 1000; i = 2) for (j = 0; j < i; j++) cnt++; What is the final value of cnt (starting from 0)?