Pearson Edexcel · A-Level · Computer Science
Stacks and Queues
Master the core principles of Stacks and Queues for your Edexcel A-Level Computer Science exam. This guide breaks down LIFO and FIFO structures, circular queues, and the vital role of the call stack in recursion, giving you the tools to tackle any exam question with confidence.
- 5 min read
- 3 worked examples
- 5 practice questions
- 6 key terms
Check what you remember
Read the wording for your board, then hide it and explain Abstract Data Type (ADT) in your own words. Rough notes are fine. This is a self-check, with no mark or grade.
Reference: Pearson Edexcel
A data type whose properties (data and operations) are specified independently of any particular implementation.
Study Notes

Overview
Stacks and Queues are fundamental Abstract Data Types (ADTs) that appear consistently in the Edexcel A-Level Computer Science exam. While seemingly simple, they are the building blocks for complex operations like managing subroutine calls, scheduling tasks in an operating system, and handling data buffers. An ADT is defined by its behaviour—the operations it supports—rather than its specific implementation. For the exam, you must be proficient in implementing these structures using both static arrays and dynamic linked lists, and be able to articulate the trade-offs between these methods. Examiners frequently test candidates on their ability to trace algorithms, write pseudocode for core operations (Push, Pop, Enqueue, Dequeue), and explain the mechanics of circular queues and the call stack. Mastering this topic is not just about memorising algorithms; it’s about understanding why they work and how they are applied in real-world systems, which is key to hitting the higher AO2 and AO3 assessment objectives.
Key Concepts
Concept 1: The Stack (LIFO)
A stack operates on a Last-In, First-Out (LIFO) principle. The last item added to the stack is the first one to be removed. Think of it as a stack of plates in a canteen; you add a plate to the top and you take a plate from the top.
- Push: Adds an item to the top of the stack.
- Pop: Removes the item from the top of the stack.
- Peek (or Top): Returns the top item without removing it.
- isEmpty: Checks if the stack has no items.
- isFull: Checks if the stack has reached its maximum capacity (only relevant for static implementations).
Examiners award marks for explicitly checking isFull before a Push and isEmpty before a Pop. This demonstrates robust algorithmic thinking.
Static Implementation (Array): A static stack uses a fixed-size array and a pointer, typically called Top, which tracks the index of the top element. Top is often initialised to -1 to indicate an empty stack. This implementation is fast (O(1) for all operations) but risks overflow if the number of items exceeds the array size.
Dynamic Implementation (Linked List): A dynamic stack uses a linked list of nodes. Each node contains data and a pointer to the next node. The Top pointer simply holds the memory address of the head node. This is more flexible as it only uses as much memory as needed and won't overflow unless the entire system runs out of memory (heap overflow). However, it has slightly higher memory overhead due to storing pointers.

Concept 2: The Queue (FIFO)
A queue operates on a First-In, First-Out (FIFO) principle. The first item added to the queue is the first one to be removed. This is analogous to a queue of people at a bus stop.
- Enqueue: Adds an item to the rear of the queue.
- Dequeue: Removes the item from the front of the queue.
- isEmpty / isFull: Used for checking the state of the queue.
Linear Queue: In a static array implementation, a linear queue uses two pointers: Front (or Head) and Rear (or Tail). As items are dequeued, the Front pointer moves forward, leaving unused space at the beginning of the array. This is inefficient and can lead to a state where the queue reports as full (Rear is at the end) even when there are empty slots.
Concept 3: The Circular Queue
A circular queue elegantly solves the inefficiency of a linear queue by treating the array as a ring. When a pointer reaches the end of the array, it wraps around to the beginning. This is achieved using modulo arithmetic.

Mathematical/Scientific Relationships
The most critical formula for this topic, which you must memorise, is the pointer update for a circular queue:
- To add an item (enqueue):
Rear = (Rear + 1) MOD MaxSize - To remove an item (dequeue):
Front = (Front + 1) MOD MaxSize
Here, MaxSize is the total number of slots in the array. This single line of logic is worth marks in almost every circular queue pseudocode question. Forgetting to use MOD and simply incrementing the pointer is a common mistake that leads to array index out of bounds errors.
Practical Applications
- Stacks: Used extensively for managing function calls (the call stack), parsing expressions in compilers (infix to postfix conversion), and implementing undo/redo features in software like text editors.
- Queues: Used for managing tasks in operating systems (print queues, CPU scheduling), handling data buffers in network communications, and in breadth-first search algorithms in graphs.
Visual Resources
3 diagrams and illustrations
Interactive Diagrams
2 interactive diagrams to visualise key concepts
Conceptual Flow Outline
A conceptual diagram of a stack, showing that both Push and Pop operations occur at the Top.
Conceptual Flow Outline
A conceptual diagram of a queue, showing that items are Enqueued at the Rear and Dequeued from the Front.
Worked Examples
3 worked examples — open one to explore the question and available guidance.
Practice Questions
Try the question, then reveal an answer plan or example response
Write a pseudocode algorithm for the Enqueue operation of a circular queue implemented with a static array. Your algorithm should handle the possibility of overflow.
Hint: Remember to check if the queue is full *before* attempting to add the new item. How do you check for a full circular queue?
Explain why a stack is a suitable data structure for managing recursion.
Hint: Think about the order in which function calls are made and the order in which they must return.
A circular queue of size 5 (indices 0-4) is initially empty. Front and Rear pointers are both at index 0. Trace the state of the queue, Front, and Rear after the following operations: Enqueue(A), Enqueue(B), Enqueue(C), Dequeue, Enqueue(D).
Hint: Draw the circular array and move the pointers for each step. Remember the formula: `Pointer = (Pointer + 1) MOD 5`.
State two differences between a stack and a queue.
Hint: Think about the access method and the names of the operations.
Describe a scenario where a dynamic implementation of a queue would be more appropriate than a static implementation.
Hint: Consider situations where the amount of data is unknown or changes a lot.
Exam technique
How to turn what you know into marks
How to approach the question
1. **Identify the Data Structure**: Is it a stack or a queue? Linear or circular? Static or dynamic? 2. **Identify the Command Word**: 'Trace', 'Describe', 'Compare', 'Write pseudocode'. This dictates the required response style. 3. **State Assumptions**: For pseudocode, always state your indexing convention (e.g., 0-based or 1-based). 4. **Work Methodically**: In trace questions, update pointers and array contents for every single operation. Don't skip steps.
How to structure your answer
For 'Compare' questions (6 marks), aim for three distinct comparison points (e.g., memory, speed, complexity), with a clear 'whereas' statement for each. For pseudocode, use clear variable names and indentation. For 'Explain' questions, use 'because' to link cause and effect.
Timing
Approximately 1 minute per mark. A 4-mark question should take no more than 5 minutes, allowing for reading and checking time.
Common pitfalls
- Forgetting to use the MOD operator in circular queue pointer updates. Always use `(Pointer + 1) MOD MaxSize`.
- Confusing the `Front` and `Rear` pointers in a queue. Remember: you add to the `Rear` and remove from the `Front`.
- Failing to check for `isEmpty` or `isFull` before performing an operation. This is a simple mark to gain.
- In dynamic implementations, forgetting to deallocate memory after a Pop/Dequeue, leading to a memory leak.
What the command words want
- Compare
- Identify both similarities and differences. A structured table or linked paragraphs using comparative language is best.
- Explain
- Give reasons how or why something happens. Use phrases like 'this is because...' to structure your answer.
- Describe
- Provide the key characteristics or steps of a process.
- Evaluate
- Make a justified judgement based on a consideration of different factors, concluding which is 'better' for a given scenario.
- Calculate
- Show your full working, including the formula used.
- State/Give
- Provide a concise, factual answer. No explanation needed.
Watch or listen (optional)
Test your understanding of Stacks and Queues
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
7 days Premium · Then the free plan continues · No card, no charge


