Assume that the operators +, -, × are left associative and ^ is right…

2004

Assume that the operators +, -, × are left associative and ^ is right associative. The order of precedence (from highest to lowest) is ^, x , +, -. The postfix expression corresponding to the infix expression a + b × c - d ^ e ^ f is

  1. A.

    abc × + def ^ ^ -

  2. B.

    abc × + de ^ f ^ -

  3. C.

    ab + c × d - e ^ f ^

  4. D.

    - + a × bc ^ ^ def

Attempted by 637 students.

Show answer & explanation

Correct answer: A

Correct postfix expression: a b c × + d e f ^ ^ -

Steps to convert the infix expression a + b × c - d ^ e ^ f to postfix using the given precedence and associativity:

  • Handle exponentiation first. Because ^ is right-associative, d ^ e ^ f is d ^ (e ^ f). Convert this to postfix as d e f ^ ^

  • Handle multiplication next. b × c becomes b c ×

  • Apply addition. With × higher precedence than +, form a + (b × c) and convert to postfix as a b c × +

  • Finally perform the subtraction of the exponent result from the addition result. Combine the two postfix parts: a b c × + d e f ^ ^ -

Explore the full course: Gate Guidance By Sanchit Sir