Data Structures & AlgorithmsModerateGATE CS · Product-company placement

A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is A F E C G D B and its inorder traversal (left, root, right) is A E F G C B D. What is its postorder traversal (left, right, root)?

  1. A. B D G C E F A
  2. B. E G B D C F A
  3. C. A F E C G D B
  4. D. D B C G F E A

Correct answer: B. E G B D C F A

The root is the first preorder letter; the inorder list splits the rest into left and right subtrees, and the same splitting applied recursively gives the postorder. Reversing one of the traversals is a common wrong guess.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic