📁 Paper 1 · Topic 1: Computational Thinking
1.2j Data Structures: Stacks & Queues
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
OperationStack 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

FeatureStackQueue
PrincipleLIFO — Last In First OutFIFO — First In First Out
Add operationPushEnqueue
Remove operationPopDequeue
Access pointTop onlyFront (remove), Back (add)
Real-world analogyStack of platesQueue 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
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]
✅ Mark scheme
Top: 12, Bottom: 5. [2] (Push 5→[5], Push 12→[12,5], Push 7→[7,12,5], Pop removes 7→[12,5])
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]
✅ Mark scheme
Push [1] / Pop [1] / Peek (or Top) [1] / isEmpty [1]
Topic Quiz
Q 1 of 15
You scored
out of 15
⚡ XP
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Stacks & Queues

Timed exam-style test.

← 1.2i Arrays & ListsTopic 1Next: 1.2k Records & Hash Tables →
🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year
Subscribe →