Compression

Computer Science AS · Information representation. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science AS topics

The idea

Compression makes a file smaller. A smaller file needs less storage space, is sent more quickly and uses less bandwidth, which matters for streaming and for email attachments.

Lossless compression loses no data: the original file can be rebuilt exactly. It is needed for text, program code and other files where every bit matters. Lossy compression removes data for good, choosing the detail people are least likely to notice. It gives much smaller files and is used for photographs, music and video.

Run-length encoding (RLE) is a lossless method. A run of identical values is stored once, together with a count of how many times it repeats.

Rules to remember

Common mistake

Students think compression always makes a file smaller. RLE can make a file larger when there are few repeated values, because every run still needs a count as well as a value.

Worked example

A row of 12 pixels alternates black, white, black, white to the end. Each pixel uses 1 byte. RLE stores each run as a 1-byte count and a 1-byte colour. Is RLE useful for this row?

  1. Uncompressed size = 12 pixels × 1 byte = 12 bytes.
  2. No two neighbouring pixels match, so there are 12 runs, each of length 1.
  3. RLE size = 12 runs × 2 bytes = 24 bytes.

Answer: No. RLE needs 24 bytes instead of 12, so the row becomes twice as large.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← MultimediaNetworks and network models →Take a Computer Science AS test