Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

A circular queue in an array of size 6 uses front (index of the first item) and rear (index of the next free slot), both starting at 0, with one slot kept empty. After enqueuing a, b, c, d, e, dequeuing twice, then enqueuing f and g, what are rear and the queue state?

  1. A. rear = 1 and the queue is full
  2. B. rear = 0 and the queue is full
  3. C. rear = 7 and the queue is full
  4. D. rear = 1 and one more item can be added

Correct answer: A. rear = 1 and the queue is full

After 5 enqueues rear = 5; two dequeues make front = 2; f goes to 5 (rear wraps to 0) and g to 0 (rear = 1). Now (rear + 1) mod 6 = 2 = front, so with one slot reserved the queue is full with 5 items. rear = 7 forgets the wrap-around.

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

Exams that ask this topic