Practic Mode : Paper-II & III On Topic : Data and File structures

Que : 1 . How many PUSH and POP operations will be needed to evaluate the following expression by reverse polish notation in a stack machine (A * B) + (C * D/E) ? (D-2014)

1. 4 PUSH and 3 POP instructions
2. 5 PUSH and 4 POP instructions
3. 6 PUSH and 2 POP instructions
4. 5 PUSH and 3 POP instructions
Please Select Ans Options .

Option 2 is Correct Answer.
The algorithm for evaluating any postfix expression is fairly straightforward:
While there are input tokens left
Read the next token from input.
If the token is a value
Push it onto the stack.
Otherwise, the token is an operator (operator here includes both operators and functions).
It is already known that the operator takes n arguments.
If there are fewer than n values on the stack (Error) The user has not input sufficient values in the expression.
Else, Pop the top n values from the stack.
Evaluate the operator, with the values as arguments.
Push the returned results, if any, back onto the stack.
If there is only one value in the stack
That value is the result of the calculation.
Otherwise, there are more values in the stack (Error) The user input has too many values Here
5 push and 4 pop