The following postfix expression with single-digit operands is evaluated using…

2016

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 * are evaluated are

  1. A.

    6,1

  2. B.

    5,7

  3. C.

    3,2

  4. D.

    1,5

Attempted by 336 students.

Show answer & explanation

Correct answer: A

To evaluate the postfix expression 823 ^ / 23 * + 51 * -, we use a stack. First, push operands: 8, 2, 3. Encounter ^ (exponentiation): pop 3 and 2, compute 2^3 = 8. Stack becomes [8, 8]. Next is /: pop 8 and 8, compute 8/8 = 1. Stack becomes [1]. Push next operands: 2, 3. Now encounter the first *: pop 3 and 2, compute 2*3 = 6. The stack now contains [1, 6]. Since the question asks for the top two elements after this operation, they are 6 (top) and 1 (below). Thus, the answer is '6,1'. Option A matches this result. Other options like B (5,7) or C (3,2) are incorrect because they do not reflect the actual stack state after evaluating 2*3.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro