GCSE · Computer Science · AQA · Spec 8525
Data compression
The letter E turns up everywhere and Q almost never, so why give them codes of the same length? Shorten the common ones and the message shrinks, losing nothing.
Computer Science · Huffman tree
Walk the tree, collect the code
Predict first: which character do you think is closest to the root? Walk to it and see. Then walk to the rarest one and count the turns. Every code you collect is just the 0s and 1s of your route.
1st bit → 2nd bit → 3rd bit → 4th bit
Every code starts here. Each bit you read is a turn: 0 means left, 1 means right.
5 characters, one at each end of the tree.
Characters sit only at the ends of branches, never at a fork. So once you land on a character you are finished with it, which means no code can ever be the start of another code.
Computer Science · Algorithms
Trace table — dry run the code
That tree did not appear from nowhere. Here is how it is built from the table E 8, T 5, A 3, N 2, Q 1. Step through it. A bracket like (QN) is a joined node, and the number after the colon is its frequency.
Ready when you are — step through one line at a time.
Computer Science · Run length encoding
Squash the runs
The row to encode is R R R R G G B B B B B. Step along it and watch the pairs appear.
Before you step: how many runs of identical values do you think this row has?
1 count = 12 FOR each next value in the row3 IF it matches the previous value THEN count = count + 14 ELSE write the pair (count, previous value) and set count = 15 After the last value, write the final pair
Variables
Output
Step 1: The first value is R, and we have seen one of it so far.
Step through the trace — every value is the lesson’s, not run by the page.
Predict, then check
Both rows are 12 values long. RLE writes each run as a frequency/data pair.
Row X is A A A A A A A A A A A A. Row Y is A B A B A B A B A B A B. Which row gets BIGGER after RLE?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Fewer bits, same data: how common characters get short codes, and when repeats can be squashed.
What you need to know
- Compression stores the same data in fewer bits, so it takes less storage and travels faster with less bandwidth.
- Huffman coding and run length encoding are lossless: the original is rebuilt exactly.
- In a Huffman tree the common characters are near the root with short codes, the rare ones are deep with long codes, and no code is the start of another.
- Huffman size = sum of (frequency × code length). Uncompressed size = number of characters × bits per character.
- RLE writes each run as a frequency/data pair. It shrinks data with long runs and can enlarge data that keeps changing.
The big picture
Compression stores the same data in fewer bits, which saves storage and makes sending quicker. Huffman coding gives common characters short codes and rare ones long codes, read by walking a tree from the root to a leaf. Run length encoding swaps each run of identical values for a frequency/data pair. Both are lossless, and RLE can backfire on data that keeps changing.
Key points
Worked example
Problem
Using the tree from the top of the page (E = 0, T = 10, A = 110, Q = 1110, N = 1111), decode the bit stream 0101101111.
⚠ Watch out
Treating a code as a number. The code 10 is a route (right, then left) with a length of 2, not the value ten. In size sums, multiply each frequency by its code's length, and count every character, repeats included, for ASCII.
Memory hook
Busy letters live by the front door (the root). Rare letters live at the bottom of the garden, and it takes a long walk to reach them.
Check yourself
Without looking back: why does E get a one-bit code while Q gets four bits, and what would go wrong if one code were the beginning of another?
Flashcards
(11)What does data compression do, and why bother?
What does 'lossless' mean?
ASCII codes are all the same length. How are Huffman codes different?
How do you build a Huffman tree from a frequency table?
How do you read a character's code from a Huffman tree?
While decoding, what do you do the moment you land on a leaf?
Why can a decoder tell where one Huffman code ends?
How do you work out the size of data after Huffman coding?
How do you work out the uncompressed size of text in ASCII?
What does run length encoding (RLE) do?
When does RLE help, and when can it hurt?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 2 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.