Data Structures & AlgorithmsHardGATE CS · Product-company placement

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

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

Correct answer: A. C E F D A 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