Question #18: What is the equivalent postfix expression for ((A + B) * C – (D – E) ^ (F + G))?
Options:
- AB* DE- FG+ ^-
- AB+C*DE-FG+^-
- AB+C*DE-FG+-^
- ABC*+DE-FG+-^
Solution:
Priority of the operators is as follows: 1. ( ) 2. ^ 3. * 4. +/-
Step 1: (A+B), (D-E) and (F+G) would be the highest priority => AB+ … DE- … FG+ becomes the intermediate postfix notation.
Step 2: ^ should be operated next => AB+ … DE-FG+^ … becomes the next intermediate postfix notation.
Step 3: * follows the next priority => AB+C* … DE-FG+^…
Step 4: Finally, – follows the next. => AB+C*DE-FG+^-
Hence, the correct answer is option 2.