Skip to main content
EnglandComputer ScienceSyllabus dot point

How does a queue work and where is it used?

Understand the queue abstract data type, FIFO behaviour, linear, circular and priority queues, and the enqueue and dequeue operations using front and rear pointers.

A focused answer to AQA A-Level Computer Science 4.2.2, covering the queue abstract data type, FIFO behaviour, linear, circular and priority queues, and the enqueue and dequeue operations with front and rear pointers.

Generated by Claude Opus 4.88 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The queue abstract data type
  3. Linear and circular queues
  4. Priority queues

What this dot point is asking

AQA wants you to describe a queue as an abstract data type with first-in first-out behaviour, distinguish linear, circular and priority queues, and trace the enqueue and dequeue operations using front and rear pointers.

The queue abstract data type

The main operations are enqueue (add an item at the rear), dequeue (remove and return the item at the front), isEmpty and isFull. Two pointers track the front and rear positions. The contrast with a stack is the key idea: a stack works at one end (LIFO) while a queue works at both ends (FIFO), which is why the two structures suit completely different jobs.

Linear and circular queues

ENQUEUE(item):
  IF NOT isFull THEN
    rear = (rear + 1) MOD size
    queue[rear] = item

DEQUEUE():
  IF NOT isEmpty THEN
    item = queue[front]
    front = (front + 1) MOD size
    RETURN item

A subtle point with circular queues is telling apart a full queue from an empty one, because in both the front and rear pointers can coincide. This is usually handled by keeping a separate count of items, or by leaving one slot unused as a sentinel. Examiners reward awareness that the wrap-around creates this ambiguity.

Priority queues

A priority queue removes items in order of priority rather than arrival order. Each item has a priority, and dequeue returns the highest-priority item; items of equal priority are served in FIFO order. Priority queues are used in process scheduling, where urgent tasks must run first, and in algorithms such as Dijkstra's shortest path, where the next vertex to process is always the one with the smallest tentative distance. They can be implemented by keeping the list sorted on insertion, or with a heap for efficiency.

Like a stack, a queue is an abstract data type, so the array implementation shown here is only one option; a queue can equally be built from a linked list, where enqueue adds a node at the tail and dequeue removes one from the head, growing dynamically rather than being bounded by a fixed array. The abstract behaviour (FIFO, with enqueue, dequeue, isEmpty and isFull) is what defines it, and a programmer picks the implementation to suit the situation.

Queues are everywhere in systems software because they buffer between a producer and a consumer that work at different rates. A keyboard buffer holds keystrokes until the program is ready to read them; a print spooler queues documents so they print in the order submitted; and network equipment queues packets waiting to be forwarded. In each case the FIFO discipline is what guarantees fairness, processing requests in the order they arrived, which is the conceptual reason the queue is the right structure rather than a stack.

Exam-style practice questions

Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

AQA 20184 marksA circular queue is held in an array of size 5 (indices 0 to 4). The front pointer is at index 3 and the rear pointer is at index 4. An item is enqueued. Calculate the new value of the rear pointer and explain why modulo arithmetic is used.
Show worked answer β†’

The new rear is (rear+1)β€Šmodβ€Šsize=(4+1)β€Šmodβ€Š5=0(\text{rear} + 1) \bmod \text{size} = (4 + 1) \bmod 5 = 0. So the rear pointer wraps round from index 4 back to index 0.

Modulo arithmetic is used so that when a pointer reaches the end of the array it wraps back to the start rather than running off the end. This lets the queue reuse the slots freed by dequeuing at the front, so the fixed array is used efficiently and the queue does not report full while empty slots exist at the beginning.

Markers reward the correct calculation (rear = 0) and the explanation that modulo makes the pointer wrap so freed slots are reused.

AQA 20214 marksDescribe the difference between a linear queue, a circular queue and a priority queue, giving one use of a priority queue.
Show worked answer β†’

A linear queue stores items in a fixed array with the front advancing as items are dequeued; the freed slots at the start cannot be reused, so the queue can report full while space remains. A circular queue solves this by wrapping the front and rear pointers back to the start using modulo arithmetic, reusing freed slots.

A priority queue removes items in order of priority rather than arrival order: each item has a priority and dequeue returns the highest-priority item, with FIFO order only breaking ties. A use of a priority queue is selecting the lowest-distance vertex in Dijkstra's algorithm, or scheduling higher-priority processes first.

Markers reward the distinct behaviour of each queue type and a valid use of a priority queue.

Related dot points

Sources & how we know this