GATE Computer ScienceModerateGATE CS (PYQ pattern)

Which one of the following is NOT a possible pop sequence when 1, 2, 3, 4, 5 are pushed in order (pops interleaved arbitrarily)? P: 2 1 4 3 5 Q: 3 4 2 1 5 R: 4 3 5 1 2 S: 1 5 4 3 2

  1. A. R
  2. B. P
  3. C. Q
  4. D. S

Correct answer: A. R

For R, after popping 4 and 3 the stack holds 1, 2 (2 on top), so 2 must come out before 1; R pops 1 before 2. P, Q and S are all producible.

More Programming and Data Structures (GATE) questions

Exams that ask this topic