GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Elements 1, 2, 3, 4, 5, 6 are pushed in this order onto a stack, with pops allowed at any time until all are popped. Of all possible output sequences, how many have 2 appearing before 1?

  1. A. 42
  2. B. 66
  3. C. 84
  4. D. 90

Correct answer: D. 90

There are C6 = 132 valid outputs. Enumerating them, 2 leaves before 1 in 90 (1 stays buried while 2 is popped) and 1 leaves before 2 in the other 42.

More Programming and Data Structures (GATE) questions

Exams that ask this topic