GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never shrink it. The operations are E E E E E D E E E D D E E E E E E E E E D E E E E E E E E (E = enqueue, D = dequeue). How many element copies are made in total, and what is the final capacity?

  1. A. 24 copies, capacity 32
  2. B. 28 copies, capacity 64
  3. C. 28 copies, capacity 32
  4. D. 36 copies, capacity 16

Correct answer: C. 28 copies, capacity 32

Doubling occurs whenever an enqueue finds the live size equal to the capacity. Tracing the live size through the operations triggers copies at the sizes found in the trace, totalling 28; the final capacity is 32.

More Programming and Data Structures (GATE) questions

Exams that ask this topic