The big idea: A queue is added to at one end and taken from at the other.
So the first item in is the first out — FIFO. Nobody who arrived later can get ahead.
Compare the two halves: the same items in, and the opposite order back out.
Interactive diagram
Explore the labelled diagram, charts and maps for this topic in full study mode.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
enqueue and dequeue
- enqueue(item) — join at the back
- dequeue() — leave from the front, and return
- Two different ends, which is the whole difference from a stack
- Both are O(1) when implemented properly
front and isEmpty
- front() — look at the next one out, without removing it
- isEmpty() — is anyone waiting?
- Check isEmpty before dequeuing
- Dequeuing an empty queue is an error
What makes it fair
- Order of arrival is preserved exactly
- Nothing can jump ahead
- That fairness is why it is used for shared resources
Why not a plain list: Removing from the front of an ordinary list means shifting every remaining item down one place — O(n) every time.
A proper queue structure removes from the front in constant time, which is why Python offers deque for the job.
Get feedback like a real examiner
Submit your answers and get instant feedback — what you did well, what's missing, and exactly what to write to score full marks.
Print jobs
Processes waiting for the CPU
Buffering data
Breadth-first exploration
Stack or queue, in one question: Does the most recent item matter most, or the one that has waited longest?
Most recent → stack. Longest waiting → queue. Every question here is that question in disguise.
How this is tested — you must justify FIFO from the scenario and say what a stack would get wrong. It comes up two ways:
Paper 2 — working with code
- Explain a queue and its operations, 3-5 marks
- Trace a sequence of enqueues and dequeues
- Choose between a stack and a queue
Paper 2 — the algorithmic-thinking question
- Decide from described behaviour, with no code shown
- Explain the consequence of choosing the wrong one
The classic trap: Describing a queue as "a list that things are added to". The mark is for the two ends: joining at the back and leaving from the front, so order of arrival is preserved.
A hospital reception system handles patients arriving for a walk-in clinic. Explain why a queue suits this, and what would happen with a stack.
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.