GATE 2013
April 15, 2024NTA UGC NET Dec 2023 Paper-2
April 16, 2024Prefix-Postfix-Expression
Question 3 |
The prefix equivalent of the following infix expression is:
a / b – c + d * e – a * c
a / b – c + d * e – a * c
– + – / a b c * d e * a c | |
+ – – / a b c * d e * a c | |
– + / a b c – * d e * a c | |
– – + / a b c * d e * a c |
Question 3 Explanation:
a / b – c + d * e – a * c
* Start scanning the expression from RHS.
* Push the operators on the top of the stack by ensuring that only high priority operator can be pushed over a low priority operator.
* If a low priority operator is encountered in expression while scanning it, and if top of stack have high priority operator then pop it and after that push low priority operator on top of stack.
* Print each operand just after scanning it.





* Start scanning the expression from RHS.
* Push the operators on the top of the stack by ensuring that only high priority operator can be pushed over a low priority operator.
* If a low priority operator is encountered in expression while scanning it, and if top of stack have high priority operator then pop it and after that push low priority operator on top of stack.
* Print each operand just after scanning it.
Correct Answer: A
Question 3 Explanation:
a / b – c + d * e – a * c
* Start scanning the expression from RHS.
* Push the operators on the top of the stack by ensuring that only high priority operator can be pushed over a low priority operator.
* If a low priority operator is encountered in expression while scanning it, and if top of stack have high priority operator then pop it and after that push low priority operator on top of stack.
* Print each operand just after scanning it.





* Start scanning the expression from RHS.
* Push the operators on the top of the stack by ensuring that only high priority operator can be pushed over a low priority operator.
* If a low priority operator is encountered in expression while scanning it, and if top of stack have high priority operator then pop it and after that push low priority operator on top of stack.
* Print each operand just after scanning it.