Data Structures & AlgorithmsModerateTCS Digital · Infosys SP

A circular queue in an array of size n uses front and rear indices and keeps one slot always empty. What is the maximum number of elements it can hold, and how is 'full' detected?

  1. A. n − 1; full when rear = n − 1
  2. B. n; full when rear = front
  3. C. n − 1; full when (rear + 1) mod n = front
  4. D. n; full when (rear + 1) mod n = front

Correct answer: C. n − 1; full when (rear + 1) mod n = front

If all n slots could be filled, front = rear would mean both empty and full. Sacrificing one slot makes 'full' the state (rear + 1) mod n = front, while front = rear still means empty.

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

Exams that ask this topic