Compute circular-array indices after wraparound

A print server stores waiting jobs in a circular array queue with capacity 8, using indices 0 to 7. It tracks front, the index of the oldest job, and size, the number of jobs stored. The next enqueue writes to index (front+size) mod 8(\text{front} + \text{size}) \bmod 8, and a dequeue advances front by one position, wrapping from 7 back to 0.


At the start, front is 5 and size is 3. The server then performs four enqueue operations followed by two dequeue operations, and none of them fails.


Give each of the following as a whole number:

  • the value of front after all six operations
  • the index the next enqueue would write to
  • the value of size
  • how many more enqueues can succeed before the queue is full
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Queues Questions: