Data Structures & AlgorithmsHardGATE CS · Product placement

How many different pop sequences are possible when 6 distinct items are pushed onto a stack in a fixed order, with pops allowed at any time?

  1. A. 42
  2. B. 132
  3. C. 64
  4. D. 720

Correct answer: B. 132

The number of valid stack permutations of n items is the Catalan number C(2n, n)/(n + 1); for n = 6 that is 924/7 = 132. 42 is the value for n = 5.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic