UGC-NET Jun 2012 · Stacks

MCQ · 2 marks · Problem PROG-DSTR-0042

The following postfix expression is evaluated using a stack. 823^/23*+51*- . The top two elements of the stack after first * is evaluated
  1. A
    6,1
  2. B
    5, 7
  3. C
    3,2
  4. D
    1, 5

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

Show the worked solutionScan \(8\ 2\ 3\ \wedge\ /\ 2\ 3\ *\ +\ 5\ 1\ *\ -\) (stack bottom to top):\[8\to[8],\ 2\to[8,2],\ 3\to[8,2,3],\ \wedge:\ 2^3=8\to[8,8],\]\[/:\ 8/8=1\to[1],\ 2\to[1,2],\ 3\to[1,2,3],\ *:\ 2\cdot3=6\to[1,6].\]After the first \(*\) the top two elements are 6 (top) and 1.Answer: A

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