Compression Cambridge IGCSE Computer Science revision

Not started

Learn it

In plain words

Compression makes a file smaller, so it takes up less room and travels faster. There are two ways to do it.

Lossy compression throws some of the data away for good, choosing the parts you are least likely to miss. Lossless compression finds a cleverer way to write the same data, so nothing is lost.

6 things to know

  1. Compression reduces the size of a file.
  2. A smaller file needs less storage space, less bandwidth to send, and a shorter transmission time.
  3. Lossy compression permanently removes data. The original file cannot be got back. Examples: reducing the resolution or colour depth of an image, or the sample rate or resolution of a sound.
  4. Lossless compression reduces file size with no permanent loss of data. The original file can be rebuilt exactly.
  5. Run-length encoding (RLE) is lossless. It replaces a run of identical values with one copy of the value and a count of how many times it repeats.
  6. Text and program files must use lossless compression: a missing character or instruction would ruin them.

Worked example

Use run-length encoding to compress the row of pixels WWWWWBBBWW, where W is white and B is black.

  1. Count each run of the same colour: five whites, three blacks, two whites.
  2. Write each run as a count and a value: 5W 3B 2W.
  3. Ten values have been stored as three pairs.

Tips and tricks

  • RLE only helps when the same value is repeated many times in a row. On data with few repeats it can make the file bigger.
  • For "lossy", write the word "permanently". The point is that the removed data cannot be recovered.
6 questions, about 2 minutes.

It lands in your notebook with its questions as flashcards.

Compression: 6 questions and answers

These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.

  1. What is the main purpose of compression?
    • to make a file more secure
    • to reduce the size of a file (the answer)
    • to improve the quality of a file
    • to check a file for errors

    A smaller file is quicker to send and takes less space.

  2. What does lossy compression do?
    • It permanently removes some of the data. (the answer)
    • It keeps all of the data.
    • It encrypts the data.
    • It makes the file larger.

    The removed data cannot be recovered.

  3. Which file should be compressed using a lossless method?
    • a holiday photograph
    • a music track
    • a text document (the answer)
    • a video clip

    Every character matters in a text file, so no data may be lost.

  4. What does run-length encoding produce from AAAABBBCCD?
    • 4A3B2C
    • 4A3B2C1D (the answer)
    • A4B3C2D1E
    • ABCD

    Four As, three Bs, two Cs and one D.

  5. Why is a compressed file quicker to send over a network?
    • It is encrypted.
    • There is less data to transmit. (the answer)
    • It travels along a different cable.
    • It is sent as a single packet.

    Fewer bits take less time and less bandwidth.

  6. For which data would run-length encoding work badly?Stretch
    • an image with large areas of one colour
    • a row of 200 identical pixels
    • a photograph in which nearly every pixel is a different colour (the answer)
    • a black and white logo

    With few repeated values in a row, there are no long runs to shorten.

Still stuck on this one?Ask in the Papermunch Discord, or help someone else who is. Discord is for ages 13 and up.Join the server

Things you can type

Or go straight to

Or browse a shelf