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?

  1. A. 5 15 25 20 10 35 45 50 40 30
  2. B. 50 45 40 35 30 25 20 15 10 5
  3. C. 30 40 50 45 35 10 20 25 15 5
  4. 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.

More Programming and Data Structures (GATE) questions

Exams that ask this topic