Multiple choice

Find out the preorder traversal of the binary tree if the postorder traversal is S T Q U R P and inorder traversal is S Q T P R U.

  1. P Q S T R U

  2. P Q R S T U

  3. P Q S R U T

  4. Q S T P R U

  5. P Q S R T U

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is the correct preorder traversal of the binary tree. Here, we first create the tree using postorder and inorder traversals. Then, find out the preorder traversal. First select root from given postorder that is P, now select its left subtree [LST] nodes and right subtree [RST] nodes from inorder. The LST node of root P is S Q T and RST nodes of P is R U. Now, take S Q T and apply the same process. Here, we get root node Q from postorder [S T Q] and its LST and RST nodes from inoder [S Q T]. Similary, we take R U and apply the same process. Here, we get root node R from postorder [U R] and its LST and RST nodes from inoder [R U].