UGC-NET Jul 2016 · Stacks

MCQ · 2 marks · Problem PROG-DSTR-0040

Consider the following operations performed on a stack of size 5:
Push (a); Pop(); Push(b); Push(c); Pop();
Push(d); Pop(); Pop(); Push(e)
Which of the following statements is correct?
  1. A
    Underflow occurs
  2. B
    Stack operations are performed smoothly
  3. C
    Overflow occurs
  4. D
    None of the above

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

Show the worked solutionTrack the number of items (capacity 5):\[\text{Push }a:1,\ \text{Pop}:0,\ \text{Push }b:1,\ \text{Push }c:2,\ \text{Pop}:1,\]\[\text{Push }d:2,\ \text{Pop}:1,\ \text{Pop}:0,\ \text{Push }e:1.\]Every pop finds at least one item on the stack and the count never exceeds 5, so there is neither underflow nor overflow.Answer: B

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