UGC-NET Jun 2012 · Stacks

MCQ · 2 marks · Problem PROG-DSTR-0030

The postfix expression AB + CD -* can be evaluated using a
  1. A
    stack
  2. B
    tree
  3. C
    queue
  4. D
    linked list

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionA postfix expression is evaluated with a stack: push each operand; on an operator, pop two operands, apply it and push the result. For \(AB+CD-*\): push A, B; + gives \(A+B\); push C, D; \(-\) gives \(C-D\); \(*\) gives \((A+B)(C-D)\), the only item left on the stack.(B) A tree represents the expression but is not the evaluation device here — incorrect.(C), (D) A queue or plain list does not give last-in first-out access to the latest operands — incorrect.Answer: A

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com