Data Structures & AlgorithmsHardGATE CS · Product-company placement

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

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

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

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