Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

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

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

Correct answer: C. C B A F E D

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