Data Structures & AlgorithmsHardGATE CS · Product-company placement

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

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

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

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