GATE Computer ScienceVery hardGATE CS (PYQ pattern)

An input-restricted double-ended queue lets items 1, 2, 3, 4, 5 be inserted only at the rear (in that order) while removals are allowed at both the front and the rear, interleaved arbitrarily. How many distinct output permutations of 1..5 can be produced?

  1. A. 90
  2. B. 42
  3. C. 120
  4. D. 74

Correct answer: A. 90

A plain stack gives C5 = 42 and a plain queue gives 1. Allowing removal at both ends gives 90 distinct outputs (the large Schroder number), found by exploring every interleaving of insert, remove-front and remove-rear.

More Programming and Data Structures (GATE) questions

Exams that ask this topic