The following postfix expression with single digit operands is evaluated using a stack: 3 6...
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
The following postfix expression with single digit operands is evaluated using a stack:
3 6 * 9 3 / / 2 ^ 5 +
Note: ^ is the exponentiation operator.
The top two elements of the stack after ^ is evaluated are:
Show answer & explanation
After evaluating the postfix expression up to and including the ^ operator, the stack contains [36, 5, ...]. The top two elements are 5 (top) and 36 (second from top). The ^ operator computes 36^2 = 1296, which is then added to 5 in the final step, but the question asks specifically for the state after ^ is evaluated, before the final + operation.
Step-by-step Derivation:
Step-by-step postfix evaluation:
- Push 3 → Stack: [3]
- Push 6 → Stack: [3, 6]
- : Pop 6, 3 → 3*6=18 → Push 18 → Stack: [18]
- Push 9 → Stack: [18, 9]
- Push 3 → Stack: [18, 9, 3]
- / : Pop 3, 9 → 9/3=3 → Push 3 → Stack: [18, 3]
- / : Pop 3, 18 → 18/3=6 → Push 6 → Stack: [6]
- Push 2 → Stack: [6, 2]
- ^ : Pop 2, 6 → 6^2=36 → Push 36 → Stack: [36]
- Push 5 → Stack: [36, 5]
After ^ is evaluated, the stack is [36, 5]. Reading top to bottom, the top two elements are: 5 (top), 36 (second).