📄 Paper 2 · 4.5 Data Representation
4.5.6c Data Compression
AQA 7517 · A-Level Computer Science · ~14 min read

Why Compress Data?

Compression reduces file sizes to save storage space and reduce transmission time when sending data over networks. This is critical for streaming, web delivery, and storage of large media files.

Lossy Compression

Lossy compression permanently removes data — specifically data deemed less important or imperceptible to humans. The original data cannot be recovered after decompression. Achieves high compression ratios.

Examples

  • JPEG — removes high-frequency (fine) image detail; saves with visible artifacts at low quality
  • MP3/AAC — removes frequencies outside human hearing range (psychoacoustics)
  • MP4/H.264 — removes redundant frames in video, uses inter-frame compression

When to use lossy

Suitable for images/audio/video where small quality loss is acceptable: websites, streaming services, social media. Not suitable for text, code, or medical imagery where every bit matters.

Lossless Compression

Lossless compression preserves all original data — decompression produces an exact copy of the original file. Lower compression ratios than lossy, but no data is lost.

Examples

  • PNG — lossless image compression (uses LZ77 / DEFLATE)
  • ZIP / GZip — general file compression; widely used for software distribution
  • FLAC — lossless audio
  • GIF — lossless but limited to 256 colours

When to use lossless

Essential for executable files, text documents, source code, spreadsheets, medical scans, legal documents — any data where exact reproduction is critical.

Run-Length Encoding (RLE)

A simple lossless algorithm. Consecutive repeated values are replaced by a count and the value. Works well when data has many repeated consecutive values (runs).

Example

Original: AAAAABBBBBBBCCCDDDDDD (21 characters)

RLE encoded: 5A7B3C6D (8 characters) — saves 62%!

Limitation: if there are few or no repeated values, RLE can actually increase file size (e.g. ABCDEFG becomes 1A1B1C1D1E1F1G).

Huffman Encoding

A more sophisticated lossless algorithm. Frequently occurring characters are assigned shorter binary codes; rare characters get longer codes. This produces shorter overall file sizes for typical data.

How it works

  • Count frequency of each character in the data
  • Build a binary tree (Huffman tree) — lowest frequency nodes at the bottom
  • Assign 0 for left branches, 1 for right branches (or vice versa)
  • Each character's code = path from root to that leaf

Example

CharacterFrequencyFixed 3-bit codeHuffman codeBits used
A4000001
B30001102
C200101103
D100111113

Fixed encoding: 100 × 3 = 300 bits. Huffman: (40×1)+(30×2)+(20×3)+(10×3) = 40+60+60+30 = 190 bits. Saving: 37%.

Compression Ratio

Compression ratio = original size ÷ compressed size. A ratio of 4:1 means the compressed file is a quarter of the original size. Higher = more compressed.

Exam tip: AQA requires you to understand RLE and Huffman encoding in detail. Be able to: apply RLE to a string; trace through a Huffman tree to find codes; calculate bits used before and after Huffman encoding. Know the key distinctions: lossy removes data permanently, lossless is reversible. Be able to name appropriate use cases for each type and give specific format examples.
Click through the slides at your own pace. Use arrow keys or click to advance.
Click slide or press arrow keys to navigate

Worksheet — 4.5.6c Data Compression

8 questions · instantly marked · AQA 7517 standard

Q1Explain the difference between lossy and lossless compression. Give one example format of each.[4]
✅ Mark scheme
Mark scheme
Lossy: permanently removes data / original cannot be fully recovered [1]; example: JPEG, MP3 or MP4 [1]. Lossless: all original data is preserved / exact copy can be reconstructed on decompression [1]; example: PNG, ZIP, GIF, FLAC [1].
Q2Apply run-length encoding (RLE) to the following bitmap data. Show the encoded result: WWWWWWBBBBWWWWWWWWWWBB[3]
✅ Mark scheme
Mark scheme
Correct identification of runs: 6W, 4B, 10W, 2B [1]; encoded as: 6W4B10W2B [1]; original = 22 characters, encoded = 8 characters — demonstrates compression saving [1].
Q3Explain why RLE might be ineffective for compressing a photograph.[2]
✅ Mark scheme
Mark scheme
Photographs contain many different pixel colours with few consecutive repeated values/runs [1]; RLE requires consecutive repeats to compress effectively — without them the encoded data can be larger than the original [1].
Q4A file contains characters with frequencies: A=50, B=30, C=15, D=5. Using Huffman encoding principles, calculate the total bits needed to store 100 characters if A gets code 0, B gets code 10, C gets code 110, D gets code 111. Compare this to fixed 2-bit encoding.[4]
✅ Mark scheme
Mark scheme
Huffman: (50×1)+(30×2)+(15×3)+(5×3) = 50+60+45+15 = 170 bits [1]; fixed 2-bit: 100×2=200 bits [1]; Huffman saves 30 bits (15%) compared to fixed encoding [1]; Huffman codes frequent characters with short codes, saving overall bits [1].
Q5A medical image is 45 MB uncompressed. After lossy compression it is 3 MB. After lossless compression it is 22 MB. Explain which format should be used and why.[3]
✅ Mark scheme
Mark scheme
Lossless compression should be used [1]; medical images must not lose any detail as even small errors could affect diagnosis / patient safety [1]; lossy compression permanently discards data which could remove clinically significant information [1].
Q6State two reasons why a video streaming service might use lossy compression.[2]
✅ Mark scheme
Mark scheme
Any two of: significantly smaller file sizes allow faster transmission / less bandwidth [1]; reduced storage costs on servers [1]; quality loss is imperceptible to typical viewers over streaming [1]; lossless compression of video would result in extremely large files unsuitable for streaming [1].
Q7Describe how Huffman encoding produces shorter codes for frequent characters.[3]
✅ Mark scheme
Mark scheme
Character frequencies are counted [1]; a binary tree is built placing highest-frequency characters closer to the root [1]; the path from root to each character determines its binary code — frequent characters have shorter paths = shorter codes, rare characters have longer paths = longer codes [1].
Q8A file has compression ratio 8:1. If the original file is 200 MB, calculate the compressed file size. Explain what this ratio means.[3]
✅ Mark scheme
Mark scheme
Compressed size = 200 ÷ 8 = 25 MB [1]; compression ratio 8:1 means for every 8 units of original data, only 1 unit of compressed data is stored [1]; so the compressed file is one-eighth the size of the original [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 9
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — Data Compression

10 questions · 10 minutes

← 4.5.6b Representing Sound
43 of 70 · AQA 7517
4.5.6d Encryption →