Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

A circular queue is implemented in an array of size 6 with front = 4 and rear = 0 (rear indexes the last stored element, the queue is non-empty and wraps around). How many elements does it hold?

  1. A. 5
  2. B. -4
  3. C. 3
  4. D. -3

Correct answer: C. 3

Count = ((rear − front + n) mod n) + 1 = ((0−4+6) mod 6) + 1 = 3.

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

Exams that ask this topic