Data Structures & AlgorithmsVery hard

Why is the number of Dyck-word stack sequences with n pushes and n pops equal to a Catalan number?

  1. A. Valid push/pop sequences are balanced parenthesis words, and balanced words of n pairs are counted by the Catalan number.
  2. B. Each push can be followed by any number of pops, which gives a power of two.
  3. C. The sequences are simply permutations of n elements.
  4. D. Each sequence must alternate push and pop, so there is only one.

Correct answer: A. Valid push/pop sequences are balanced parenthesis words, and balanced words of n pairs are counted by the Catalan number.

Pushes correspond to opening brackets and pops to closing ones, with the constraint that the stack never goes negative. Those balanced words are counted by C(n) = (2n)!/((n+1)!·n!).

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

Exams that ask this topic