IAE Academy

ISRO CS 2023 Q.17: solution and answer

ISRO 2023 · CSQ.17 · 1 mark · MCQ

In Reverse Polish notation, expression A*B+C*D is written as

  1. (A)

    AB*CD*+

  2. (B)

    A*BCD*+

  3. (C)

    AB*CD+*

  4. (D)

    A*B*CD+

See the question in the paper

Answer and solution

ANSWER

The postfix form is , option (a).

Official answer: ASource: ISRO's revised and final answer key of 16 February 2024

  1. Reverse Polish (postfix) notation writes each operator after its two operands, so no brackets are needed.

  2. Precedence: * binds tighter than +, so the expression is .

  3. Convert the left product: .

  4. Convert the right product: .

  5. The + joins the two results, so it goes after both: , which is .

  6. Check by evaluating the string with a stack: push A, push B, * gives ; push C, push D, * gives ; + adds the two results. This is the original expression.

  7. Option (b) A*BCD*+ and option (d) A*B*CD+ are not valid postfix: each has a * right after the single operand A, with no second operand before it. Option (c) AB*CD+* evaluates to , a different expression.

KEY IDEA

Apply precedence first, then place every operator after its two operands: the two products are converted separately and the + goes last.

WATCH OUT FOR

Leaving an operator between operands, as in infix, or placing + before the second product so that it ends up applied to the wrong operands, as in .

From the ISRO CS 2023 paper. Every question of this paper · The full paper (PDF, ISRO) · All 1 ISRO Linear structures question, with notes