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

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

  1. A. 6
  2. B. 3
  3. C. 4
  4. D. 2

Correct answer: D. 2

Count = ((rear − front + n) mod n) + 1 = ((5−4+7) mod 7) + 1 = 2.

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

Exams that ask this topic