Skip to content
Official PYQ · 1991

GATE CS 1991 Q03 — Arrays, Stacks and Queues

Explain with AI

The following sequence of operations is performed on a stack:

PUSH(10),PUSH(20),POP,PUSH(10),PUSH(20),POP,POP,POP,PUSH(20),POPPUSH (10), PUSH (20), POP, PUSH (10), PUSH (20), POP, POP, POP, PUSH (20), POP

The sequence of values popped out is

Choose one option
View worked solution

Answer: B

We can trace the state of the stack and the sequence of popped values step-by-step:

  1. PUSH(10): Stack = [10][10]
  2. PUSH(20): Stack = [10,20][10, 20]
  3. POP: Pops 2020. Stack = [10][10]
  4. PUSH(10): Stack = [10,10][10, 10]
  5. PUSH(20): Stack = [10,10,20][10, 10, 20]
  6. POP: Pops 2020. Stack = [10,10][10, 10]
  7. POP: Pops 1010. Stack = [10][10]
  8. POP: Pops 1010. Stack = [][]
  9. PUSH(20): Stack = [20][20]
  10. POP: Pops 2020. Stack = [][]

Combining the popped values in order, we get: 20,20,10,10,2020, 20, 10, 10, 20.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions