Data Structures & AlgorithmsHardGATE CS · Advanced

Every node of a binary tree has either 0 or 2 children. Its preorder traversal is W S M Q R P K Z T and its postorder traversal is Q R M K Z P S T W. What is its inorder traversal?

  1. A. T W Q M R S K P Z
  2. B. T W Z P K S R M Q
  3. C. Q M R S K P Z W T
  4. D. R M Q S K P Z W T

Correct answer: C. Q M R S K P Z W T

For a full binary tree the pair (preorder, postorder) is unique: the node after the root in preorder is the left child, and its position in the postorder gives the size of the left subtree. Rebuild recursively, then read inorder.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic