GATE / CS ARCHIVE

GATE CSE 2000 / QUESTION 13(b)(i)

Trace first postfix prefix

Data Structures · Stacks & Queues · Full GATE CSE 2000 paper

GATE 2000, Q13(b)(i) Descriptive
Report issue

Stacks & Queues

Question 13(b)(i), GATE 2000: Evaluate the postfix expression 5 2 * 3 4 + 5 2 * * + with single-digit operands, binary addition and multiplication. Stacks below are bottom-to-top. Give the stack after prefix 5 2 * 3 4 +.
Question 13(b)(i), GATE 2000: Evaluate the postfix expression 5 2 * 3 4 + 5 2 * * + with single-digit operands, binary addition and multiplication. Stacks below are bottom-to-top. Give the stack after prefix 5 2 * 3 4 +.
Question 13(b)(i), GATE 2000: Evaluate the postfix expression 5 2 * 3 4 + 5 2 * * + with single-digit operands, binary addition and multiplication. Stacks below are bottom-to-top. Give the stack after prefix 5 2 * 3 4 +.
Tap to enlarge
Answer & solution

Answer: [10, 7], top = 7 (no official key was published)

Step through it (7 steps)

Read left to right. An operand is pushed; an operator pops the right operand first and then the left, computes left operator right, and pushes the result. The successive stacks are [5], [5,2], [10], [10,3], [10,3,4], [10,7]. The multiplication consumes 5 and 2 to produce 10; the addition consumes only 3 and 4 to produce 7. The earlier 10 remains below the new result. Therefore the requested stack is bottom [10,7] top.

Original paper, page 8