Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

Exactly how many permutations of 1..5 can be sorted by a single stack (push and pop operations, output must be 1, 2, 3, 4, 5)?

  1. A. 120
  2. B. 42
  3. C. 32
  4. D. 60

Correct answer: B. 42

Stack-sortable permutations of length n are counted by the Catalan number C_n; C_5 = 42. Counting all 5! = 120 permutations ignores the stack constraint.

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

Exams that ask this topic