Consider the following tree If the post order traversal gives ab-cd*+ then the…

2017

Consider the following tree

image.png

If the post order traversal gives ab-cd*+ then the label of the nodes 1,2,3,… will be

  1. A.

    +,-,*,a,b,c,d

  2. B.

    a,-,b,+,c,*,d

  3. C.

    a,b,c,d,-,*,+

  4. D.

    -,a,b,+,*,c,d

Attempted by 285 students.

Show answer & explanation

Correct answer: A

Post-order traversal visits nodes in the order: Left Subtree, Right Subtree, Root.

Given the post-order string 'ab-cd*+', we can reconstruct the expression tree: 1. Operands 'a' and 'b' form a subtree with root '-'. 2. Operands 'c' and 'd' form a subtree with root '*'. 3. The final operator '+' combines the '-' and '*' subtrees as its left and right children respectively.

The specific labels for nodes 1 through 6 depend on the diagram's numbering convention (e.g., level-order or pre-order), which is typically provided in the question image.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro