GATE / CS ARCHIVE

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

Finish postfix evaluation

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

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

Stacks & Queues

Question 13(b)(iii), 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 at the end.
Question 13(b)(iii), 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 at the end.
Question 13(b)(iii), 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 at the end.
Tap to enlarge
Answer & solution

Answer: [80] (no official key was published)

Step through it (12 steps)

After 5 2 * 3 4 + 5 2 the stack is [10,7,5,2]. The next * replaces the top two entries 5,2 by 10, leaving [10,7,10]. The following * replaces 7,10 by 70, leaving [10,70]. Finally + replaces 10,70 by 80, leaving [80]. There are six operand tokens and five binary operators, so a valid complete evaluation must leave exactly one entry. In infix form the expression is (5*2)+((3+4)*(5*2))=10+7*10=80.

Original paper, page 8