Data Structures & AlgorithmsHardGATE CS

A circular queue is stored in an array of size 6 (indices 0-5). Initially empty, front = 0, and an enqueue stores at index (front + count) mod 6 (rejected if count = 6); a dequeue advances front by 1 mod 6. The operations are E10 E20 E30 E40 E50 D D E60 E70 D E80 E90 D D E11 (E = enqueue the value, D = dequeue). After all operations, what are the index of the front element and the index of the rear (last) element?

  1. A. front = 5, rear = 4
  2. B. front = 4, rear = 2
  3. C. front = 5, rear = 3
  4. D. front = 0, rear = 3

Correct answer: C. front = 5, rear = 3

Tracking count: after the first five enqueues count = 5; two dequeues leave 3 (front = 2); E60 and E70 bring it to 5, D leaves 4 (front = 3), E80 and E90 would reach 6 (all accepted), then D D leave 4 (front = 5), and E11 gives count = 5. The front is index 5 and the rear is (5 + 5 − 1) mod 6 = 3. Final array: [70, 80, 90, 11, None, 60].

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

Exams that ask this topic