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

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

  1. A. 7
  2. B. 9
  3. C. 1
  4. D. 8

Correct answer: D. 8

Count = ((rear - front + n) mod n) + 1 = ((8-1+9) mod 9) + 1 = 8.

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

Exams that ask this topic