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

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

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

Correct answer: D. 1

Count = ((rear − front + n) mod n) + 1 = ((6−6+10) mod 10) + 1 = 1.

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

Exams that ask this topic