The GATE Grind

GATE 2016 CS (CS2) – Question 46

Programming and Data Structures · Trees and Binary Search Trees · 2 marks · Multiple choice

New-order traversal visits root, then right subtree in New-order, then left subtree in New-order. Find it for the tree of postfix expression “3 4 * 5 - 2 ^ 6 7 * 1 + -”.

  1. + - 1 6 7 * 2 ^ 5 - 3 4 *
  2. - + 1 * 6 7 ^ 2 - 5 * 3 4
  3. - + 1 * 7 6 ^ 2 - 5 * 4 3
  4. 1 7 6 * + 2 5 4 3 * - ^ -

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) - + 1 * 7 6 ^ 2 - 5 * 4 3

Explanation

The final minus is the root. Its right subtree (6×7)+1 is visited as “+ 1 * 7 6”. Its left subtree ((3×4)−5)^2 is visited as “^ 2 - 5 * 4 3”. Combining root, right and left gives “- + 1 * 7 6 ^ 2 - 5 * 4 3”, C.

More Trees and Binary Search Trees questions

All Trees and Binary Search Trees questions →