GATE Computer ScienceHardGATE CS (PYQ pattern)
Keys 30, 10, 40, 5, 20, 35, 50, 15, 25, 45 are inserted in this order into an empty BST, and then the left and right pointers of every node are swapped (the tree is mirrored). What is the postorder traversal of the mirrored tree?
- A. 5 15 25 20 10 35 45 50 40 30
- B. 50 45 40 35 30 25 20 15 10 5
- C. 30 40 50 45 35 10 20 25 15 5
- D. 45 50 35 40 25 15 20 5 10 30
Correct answer: D. 45 50 35 40 25 15 20 5 10 30
Postorder of the mirror is: mirror-post(right), mirror-post(left), root. By induction this is exactly the reverse of the original preorder (root, left, right). The original preorder is 30 10 5 20 15 25 40 35 50 45, so the answer is its reverse. The reverse of the inorder is the mirror's inorder, not its postorder.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A complete binary tree with 20 nodes is stored in A[1..20] with A[i] = i, the children of i at 2i and 2i + 1. The routine v(i) does: if i…
- int a[4][3] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; int (p)[3] = a; p += 2; int q = p + 1; printf("%d %d %d %d", ((p - 1) + 2), (p)[1]…
- char n[] = {"delhi", "mumbai", "chennai", "kolkata"}; char pp = n; ++pp; printf("%s ", pp + 2); printf("%c ", ++pp); printf("%s ", pp[-1]…
- char src[] = "gate0cse"; char dst[20]; char d = dst, s = src; int n = 0; while ((d++ = s++)) n++; printf("%d %zu %zu", n, sizeof(src)…
- What is the total number of characters written to the output by this program? (Assume arguments of the last printf are evaluated before…
- unsigned char a = 250, b = 10; unsigned char c = a + b; int x = -1; unsigned int y = 1; printf("%d %d %d %d", c, a + b, x < y, (unsigned…