Data Structures & AlgorithmsModerateGATE CS · Product-company placement

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

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

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

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