Edexcel 1CP2 · GCSE Computer Science · ~13 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz
The Stack
A stack is a data structure that follows the LIFO principle — Last In, First Out. The most recently added item is the first one to be removed, like a stack of plates.
Stack operations
Push — add an item to the top of the stack
Pop — remove and return the item from the top
Peek / Top — view the top item without removing it
isEmpty — check whether the stack is empty
Stack pointer
A stack pointer keeps track of the top of the stack. When you push, it increments; when you pop, it decrements. If you try to pop from an empty stack, you get a stack underflow error. If the stack is full and you push, you get a stack overflow.
Real-world uses of stacks
Browser back button — pages are stored in a stack; each back press pops one off
Undo feature in editors — each action is pushed; undo pops the last action
Call stack in programming — managing function/subroutine calls
Checking balanced brackets in code
Operation
Stack state (top → bottom)
Push(10)
[10]
Push(20)
[20, 10]
Push(30)
[30, 20, 10]
Pop()
[20, 10] → returns 30
Peek()
[20, 10] → returns 20 (no change)
The Queue
A queue follows the FIFO principle — First In, First Out. The first item added is the first to be removed, like a queue of people waiting.
Queue operations
Enqueue — add an item to the back of the queue
Dequeue — remove and return an item from the front
Peek / Front — view the front item without removing it
isEmpty — check whether the queue is empty
Real-world uses of queues
Print spooler — documents queue up to be printed in order
CPU scheduling — processes wait in a queue for processor time
Keyboard buffer — keystrokes are stored in a queue and processed in order
Network packet handling — data packets processed in arrival order
Stack vs Queue Comparison
Feature
Stack
Queue
Principle
LIFO — Last In First Out
FIFO — First In First Out
Add operation
Push
Enqueue
Remove operation
Pop
Dequeue
Access point
Top only
Front (remove), Back (add)
Real-world analogy
Stack of plates
Queue of people
Exam tip: Know the precise terminology — push/pop for stacks, enqueue/dequeue for queues. Questions often ask you to trace through a sequence of operations and state the contents of the structure after each step.
⚠️ Common Mistakes
Confusing LIFO and FIFO — stacks are LIFO (last in = first out); queues are FIFO (first in = first out)
Using "push/pop" for a queue or "enqueue/dequeue" for a stack — use the correct terms
Forgetting the stack pointer concept — the top of the stack is tracked by the pointer
Stack overflow vs stack underflow: overflow = push to full stack; underflow = pop from empty stack
✅ Notes completed!
▶
Video coming soon
In production
Key points
Stacks: LIFO principle with push and pop operations demonstrated
Stack pointer and overflow/underflow errors
Queues: FIFO principle with enqueue and dequeue operations
Real-world examples for both stacks and queues
Trace questions: tracking stack/queue contents step by step
Click slide or press arrow keys to navigate
✍️
Worksheet — 1.2j Stacks & Queues
8 Edexcel-style questions · AI-marked
Q1State the principle that describes how a stack operates.[1]
✅ Mark scheme
LIFO — Last In, First Out. [1]
Q2The following operations are performed on an empty stack: Push(5), Push(12), Push(7), Pop(). State the contents of the stack after all four operations, from top to bottom.[2]
Q3Describe one real-world application of a stack and explain why a stack is appropriate for this use.[3]
✅ Mark scheme
E.g. Browser back button [1] — each page visited is pushed onto the stack [1]; pressing back pops the most recent page, returning to the previous one (LIFO behaviour) [1].
Q4What is the difference between a stack overflow and a stack underflow?[2]
✅ Mark scheme
Stack overflow occurs when you try to push to a full stack [1]; stack underflow occurs when you try to pop from an empty stack [1].
Q5The following operations are performed on an empty queue: Enqueue(A), Enqueue(B), Enqueue(C), Dequeue(). What value is returned by Dequeue() and what is in the queue afterwards?[2]
✅ Mark scheme
Returns A [1]; queue contains B, C (front to back) [1]. (First in, first out — A was enqueued first.)
Q6Compare stacks and queues by completing this sentence: A stack uses _______ (LIFO/FIFO) and a queue uses _______ (LIFO/FIFO).[2]
✅ Mark scheme
Stack uses LIFO [1]; queue uses FIFO [1].
Q7Describe one real-world application of a queue and explain why a queue is appropriate.[3]
✅ Mark scheme
E.g. Print spooler [1] — documents are added to the queue as they are sent to the printer [1]; the first document sent is the first to be printed (FIFO), which is fair and preserves order [1].
Q8Name the four operations associated with a stack.[4]
Q2The operation to add an item to a stack is called:[1]
Q3Which real-world system uses a queue?[1]
Q4Stack operations: Push(1), Push(2), Push(3), Pop(). Top of stack is:[1]
Q5Trying to pop from an empty stack causes:[1]
Section B — Short Answer [5 marks]
Q6Operations: Enqueue(X), Enqueue(Y), Enqueue(Z), Dequeue(). What is returned and what remains?[3]
Mark schemeDequeue returns X [1]; queue contains Y, Z (front to back) [1]; FIFO principle — first in, first out [1].
Q7State one difference between a stack and a queue.[2]
Mark schemeA stack uses LIFO [1] whereas a queue uses FIFO [1]. / A stack removes from the top [1] whereas a queue removes from the front and adds at the back [1].