Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

A binary tree with distinct letters has preorder ABEDCF and inorder ECDFBA. What is its postorder traversal (left, right, root), written as a string of letters?

  1. A. ABFDCE
  2. B. ABEDCF
  3. C. CFDEBA
  4. D. FCDEBA

Correct answer: C. CFDEBA

The root is the first preorder letter, and splitting the inorder sequence gives the subtrees; this yields postorder CFDEBA. Reversing the preorder or taking a level-order walk gives a different string.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic