Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 23 12 58 38 83 34 24, and its preorder traversal (root, left subtree, right subtree) is 83 23 38 58 12 24 34. Give its postorder traversal (left subtree, right subtree, root).

  1. A. 12 58 38 23 34 24 83
  2. B. 83 23 38 58 12 24 34
  3. C. 83 23 24 38 34 58 12
  4. D. 34 24 12 58 38 23 83

Correct answer: A. 12 58 38 23 34 24 83

The first preorder label is the root, and its position in the inorder sequence splits the left and right subtrees, which are then solved the same way. Postorder then lists left, right, root.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic