Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many permutations of 0, 1, 2, 3, 4 are alternating, meaning p[0] < p[1] > p[2] < p[3] > p[4]?

  1. A. 16
  2. B. 32
  3. C. 5
  4. D. 60

Correct answer: A. 16

This is the Euler zigzag number E₅ = 16 for the pattern starting with an ascent. Counting alternating permutations with a DP over the last element and the direction of the last step gives the same value.

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

Exams that ask this topic