Skip to content
Official PYQ · 1995

GATE CS 1995 Q2.21 — Arrays, Stacks and Queues

Explain with AI

The postfix expression for the infix expression A+B∗(C+D)/F+D∗EA+B*(C+D)/F+D*E is:

Choose one option
View worked solution

Answer: B

To convert the infix expression A+B∗(C+D)/F+D∗EA + B * (C + D) / F + D * E to its postfix form, we follow the standard operator precedence and associativity rules:

  1. Parentheses have the highest precedence.
  2. Multiplication (∗*) and Division (//) have the next highest precedence and are left-associative.
  3. Addition (++) has the lowest precedence and is left-associative.

Let's convert the expression step-by-step:

  • Step 1: Parentheses
    Convert (C+D)→CD+(C + D) \rightarrow CD+
    The expression becomes: A+B∗[CD+]/F+D∗EA + B * [CD+] / F + D * E
  • Step 2: Multiplication and Division (from left to right)
    First, evaluate B∗[CD+]→BCD+∗B * [CD+] \rightarrow BCD+*
    The expression becomes: A+[BCD+∗]/F+D∗EA + [BCD+*] / F + D * E

    Next, evaluate [BCD+∗]/F→BCD+∗F/[BCD+*] / F \rightarrow BCD+*F/
    The expression becomes: A+[BCD+∗F/]+D∗EA + [BCD+*F/] + D * E

    Next, evaluate D∗E→DE∗D * E \rightarrow DE*
    The expression becomes: A+[BCD+∗F/]+[DE∗]A + [BCD+*F/] + [DE*]
  • Step 3: Addition (from left to right)
    First, evaluate A+[BCD+∗F/]→ABCD+∗F/+A + [BCD+*F/] \rightarrow ABCD+*F/+
    The expression becomes: [ABCD+∗F/+]+[DE∗][ABCD+*F/+] + [DE*]

    Finally, evaluate the last addition: [ABCD+∗F/+]+[DE∗]→ABCD+∗F/DE∗++[ABCD+*F/+] + [DE*] \rightarrow ABCD+*F/DE*++

Thus, the final postfix expression is ABCD+∗F/DE∗++ABCD+*F/DE*++, which corresponds to Option B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions