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

A circular queue is implemented in an array of size 11 with front = 7 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. -2
  2. B. 9
  3. C. 10
  4. D. 8

Correct answer: C. 10

Count = ((rear − front + n) mod n) + 1 = ((5−7+11) mod 11) + 1 = 10.

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

Exams that ask this topic