Choose the correct alternatives (more than one may be correct) and write the…

1991

Choose the correct alternatives (more than one may be correct) and write the corresponding letters only. The following sequence of operations is performed on a stack:

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

The sequence of values popped out is?

  1. A.

    20, 10, 20, 10, 20

  2. B.

    20, 20, 10, 10, 20

  3. C.

    10, 20, 20, 10, 20

  4. D.

    20, 20, 10, 20, 10

Attempted by 185 students.

Show answer & explanation

Correct answer: B

A stack operates on a Last In First Out principle. Pushing 10 then 20, the first pop retrieves 20. Subsequent pushes and pops retrieve 20, then 10, then the initial 10. The final push and pop retrieve 20, resulting in the sequence 20, 20, 10, 10, 20.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir