Which RPN expression matches the infix?
Which of these is the Reverse Polish Notation (RPN) form of the infix expression a * (b + c)?
A a b + c *
B a b c + *
C a b * c +
D a * b c +
[1]
- 1
Work from the brackets out.
(b + c)becomesb c +. The multiplication then has operandsaand(b + c), so it becomesa, thenb c +, then*. - 2
Check the options. A and C calculate
(a + b) * canda * b + c. D is not RPN, because an operator sits between operands. Answer Ba b c + *(1).
Answer
B
Examiner tip
Examiner tip: in RPN the operands stay in their original order (a, b, c); only the operators move, each to just after its two operands. Use that to rule out options quickly.
Common mistake: choosing A by writing the operators in the order they appear in the infix. The brackets mean + must be applied first, so + comes before *.