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.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
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 . 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
- Understand the stack abstract data type, LIFO behaviour, the push, pop and peek operations using a stack pointer, and the use of stacks for subroutine calls and recursion.
A focused answer to AQA A-Level Computer Science 4.2.3, covering the stack abstract data type, LIFO behaviour, the push, pop and peek operations with a stack pointer, overflow and underflow, and the use of the call stack.
- Understand arrays (one, two and three dimensional), records and fields, and the difference between static and dynamic data structures.
A focused answer to AQA A-Level Computer Science 4.2.1, covering one, two and three dimensional arrays, records and fields, indexing, and the difference between static and dynamic data structures.
- Understand depth-first and breadth-first graph traversal, the data structures they use, and the pre-order, in-order and post-order tree traversal algorithms.
A focused answer to AQA A-Level Computer Science 4.3.1, covering depth-first and breadth-first graph traversal and the data structures they use, plus the pre-order, in-order and post-order tree traversal algorithms.
- Understand trees as a connected, undirected graph with no cycles, the terms root, child, parent, leaf and subtree, and the structure and use of a binary search tree.
A focused answer to AQA A-Level Computer Science 4.2.5, covering trees as connected acyclic graphs, the terminology root, child, parent and leaf, binary trees, and the structure and use of a binary search tree.
- Understand a dictionary as an abstract data type of key-value pairs, its operations, how it is typically implemented using a hash table, and when a dictionary is appropriate.
A focused answer to AQA A-Level Computer Science 4.2.7, covering the dictionary abstract data type of key-value pairs, its operations, its typical implementation using a hash table, and when to use a dictionary.
Sources & how we know this
- AQA A-level Computer Science (7517) specification β AQA (2015)