ISRO | ISRO CS 2016 | Question 24
The following postfix expression with single digit operands is evaluated using a stack:
8 2 3 ^ / 2 3 * + 5 1 * –
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are
(A) 6,1
(B) 5,7
(C) 3,2
(D) 1,5
Answer: (A)
Explanation: Given expression: 8 2 3 ^ / 2 3 * + 5 1 * –
To evaluate postfix expression:
1) if operand is encountered then Push it on the stack.
2) if operator is encountered then Pop top two elements.
3) Evaluate the result, i.e. B operator A.
4) Push result on the stack.
Following table shows the solution for the given expression:
So, after first * operator is evaluated, 6 and 1 remains on stack.
Option (A) is correct.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
23 Mar, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...