Data Structures & AlgorithmsModerateGATE CS · Product-company placement

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

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

Correct answer: D. D A F B C E

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