UGC-NET Dec 2018 · Stacks

MCQ · 2 marks · Problem PROG-DSTR-0054

Consider the following postfix expression with single digit operands : $6 \; 2 \: 3 \: ^* \: / \:  4 \: 2 \: ^* \; + \: 6 \: 8 \: ^* \: -$ The top two elements of the stack after the second $^*$ is evaluated, are :
  1. A
    $8,2$
  2. B
    $8,1$
  3. C
    $6,2$
  4. D
    $6,3$

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

Show the worked solutionHere \(^{*}\) is multiplication. Scan \(6\ 2\ 3\ *\ /\ 4\ 2\ *\ +\ 6\ 8\ *\ -\) (stack bottom to top):\[6,2,3\to[6,2,3],\ *:\ 2\cdot3=6\to[6,6],\ /:\ 6/6=1\to[1],\]\[4,2\to[1,4,2],\ *:\ 4\cdot2=8\to[1,8].\]After the second \(*\) the top two elements are 8 (top) and 1.Answer: B

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