Data Structures & AlgorithmsHardGATE CS · Product-company placement

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

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

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

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