Skip to content

Data compression: GCSE Computer Science revision notes

Compression makes files smaller, so they take up less storage space and are quicker to send or download, using less bandwidth.

In short

Compression makes files smaller, so they take up less storage space and are quicker to send or download, using less bandwidth.

For GCSE students in Years 10 and 11, on the AQA, OCR, Edexcel, Eduqas, Edexcel IGCSE and Cambridge IGCSE Computer Science courses.

Why compress files?

  • Compression makes files smaller, so they take up less storage space and are quicker to send or download, using less bandwidth.

Lossy compression

  • Lossy compression permanently removes some data, usually detail that people are unlikely to notice. It greatly reduces the file size, but the original can't be recovered exactly.
  • It is used for photos (JPEG), music (MP3) and video. It is not suitable for text or program files.

Lossless compression

  • Lossless compression makes a file smaller without losing any data, so the original can be recovered exactly.
  • It is used for text, program files and some images (PNG). It usually reduces the file size less than lossy compression.

Run-length encoding (RLE)

  • RLE stores each run of repeated data as a count and a value: AAAAABBB becomes 5A 3B. In binary, 0000011100 becomes 5 0s, 3 1s and 2 0s.
  • It works well when there are long runs of repeated values, but can make data bigger when there are few repeats.

Huffman coding

  • Huffman coding gives shorter binary codes to the characters that appear most often, using a Huffman tree. It is lossless.
  • Bits needed = the total of (frequency × code length) for each character. A text with 4 As, 2 Bs and 1 C, coded A = 0, B = 10 and C = 11, needs 4 × 1 + 2 × 2 + 1 × 2 = 10 bits, compared with 7 × 7 = 49 bits in 7-bit ASCII.

Key terms

Compression
Making a file smaller.
Lossy compression
Compression that permanently removes some data.
Lossless compression
Compression that keeps all the data, so the original can be recovered exactly.
Run-length encoding
Storing runs of repeated data as a count and a value.
Huffman coding
Lossless compression that gives shorter codes to more frequent characters.
Bandwidth
The amount of data that can be sent over a network each second.

Quick questions on Data compression

Why are files compressed?
To make them smaller, so they use less storage and transfer faster: Smaller files also use less bandwidth.
Which type of compression permanently removes data?
Lossy: The removed data can't be recovered.
Which type of compression should be used for a program file?
Lossless: Losing any data would stop the program working.
Why is lossy compression not suitable for text?
Removing data would change the text: Every character matters.
Which file type usually uses lossy compression?
MP3: MP3 removes sounds people are unlikely to hear.
What is AAAAABBB in run-length encoding?
5A 3B: Five As followed by three Bs.
When does run-length encoding work well?
When there are long runs of repeated values: Each run shrinks to a count and a value.
What does lossless compression allow?
The original file to be recovered exactly: No data is lost.
In Huffman coding, which characters get the shortest codes?
The most frequent characters: This saves the most bits overall.
With codes A = 0, B = 10 and C = 11, how many bits does 'AABC' take?
6: 1 + 1 + 2 + 2 = 6.
Is Huffman coding lossy or lossless?
Lossless: The original text can be recovered exactly.
Why might run-length encoding make a file bigger?
If there are few repeats, storing a count for every value adds data: ABC would become 1A 1B 1C.

Data compression: exam-style questions and mark schemes

  1. Which of these is an example of lossless compression? [1 mark]

    Answer: Run-length encoding

  2. Give two reasons why a music streaming service uses compression. [2 marks]

    • Smaller files stream or download faster (1)
    • They use less bandwidth, or less storage space (1)
  3. Show how the data WWWWWWBBBWW could be compressed using run-length encoding. [2 marks]

    • Correct runs: 6 W, 3 B and 2 W (1)
    • Written as count and value pairs, e.g. 6W 3B 2W (1)
  4. A text contains 4 As, 2 Bs and 1 C. Huffman coding gives A = 0, B = 10 and C = 11. How many bits are needed to store the text? [3 marks]

    • A: 4 × 1 = 4 bits (1)
    • B: 2 × 2 = 4 bits, and C: 1 × 2 = 2 bits (1)
    • Total = 10 bits (1)
  5. A website shows photos and lets people download software. Compare lossy and lossless compression, and justify which type should be used for each. [6 marks]

    • compression makes files smaller, so they download faster and take less storage
    • lossy compression permanently removes some data, such as detail people won't notice
    • lossy makes files much smaller
    • lossy suits the photos: a small loss of quality isn't noticed and pages load faster
    • lossless compression keeps all the data, so the original file can be rebuilt exactly
    • examples of lossless methods are run-length encoding and Huffman coding
    • software must use lossless: if any data were lost, the program wouldn't work
    • lossless files are not reduced as much as lossy ones

How to answer them: exam technique and command words.

Data compression: questions and answers

In Huffman coding, which characters get the shortest codes?
The most frequent characters. This saves the most bits overall.
With codes A = 0, B = 10 and C = 11, how many bits does 'AABC' take?
1 + 1 + 2 + 2 = 6.
Is Huffman coding lossy or lossless?
Lossless. The original text can be recovered exactly.

Practise Data compression: 12 questions

Download these notes as a PDF

Previous topic: Representing text, images and soundNext topic: Boolean logic and logic gates

More in Fundamentals of data representation

LycoLearn is still loading…

This can take a little longer on a busy school or home network. If nothing happens, try refreshing the page.

LycoLearn didn’t load properly

Part of it didn’t arrive. Try refreshing the page in a minute, or open LycoLearn in another browser.