Question:medium

What is the value of the postfix expression: $6\ 12\ 2\ 4\ +\ /\ *\ ?$

Show Hint

Always evaluate postfix expressions using a stack and process operators from left to right.
Updated On: Jul 6, 2026
  • 10
  • 12
  • 15
  • 18
Show Solution

The Correct Option is B

Approach Solution - 1

Step 1: Push the operands onto a stack in order: 6, 12, 2, 4.
Step 2: On seeing \(+\), pop 4 and 2, compute \(2+4=6\), push 6 back. Stack now holds 6, 12, 6.
Step 3: On seeing \(/\), pop 6 and 12, compute \(\frac{12}{6}=2\), push 2 back. Stack now holds 6, 2. On seeing \(*\), pop 2 and 6, compute \(6 \times 2 = 12\).
\[ \boxed{12} \]
Was this answer helpful?
0
Show Solution

Approach Solution -2

Another way to evaluate this is by building the expression as a binary tree from the postfix string and reading it leaf-to-root. The last operator, \(*\), becomes the root with two children: the operand 6 on one side, and the sub-tree for \(12\ 2\ 4\ +\ /\) on the other. That sub-tree's root is \(/\), with children 12 and the sub-tree for \(2\ 4\ +\), whose root is \(+\) with children 2 and 4.

  1. 10: Evaluating the tree bottom-up never produces this value at the root; it isn't reachable from combining 6, 12, 2 and 4 through one addition, one division, and one multiplication in this tree shape.
  2. 12: Bottom-up evaluation: the \(+\) leaf-pair gives \(2+4=6\); the \(/\) node then combines this with 12 to give \(\frac{12}{6}=2\); the root \(*\) node combines this with 6 to give \(6\times2=12\). This is exactly what the tree computes.
  3. 15: Reaching this would need the root operation to add rather than multiply the two children, which contradicts the tree's actual root operator.
  4. 18: Reaching this would need the division step to be skipped entirely and 6 added straight to 12, which isn't how the tree is structured.

Reading the tree from its leaves up to the root gives one unambiguous result.

Therefore, the correct answer is 12.

Was this answer helpful?
0