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.

In simpler words

Compression makes a file smaller. Small files take less space and send faster. Lossless compression keeps every bit, so you can get the exact file back. Use it for text and programs. Lossy compression throws away detail people will hardly notice. Files get much smaller, but the lost data is gone for good. Run-length encoding writes a run of the same thing once, with a count.

An everyday comparison

Writing '12 eggs' on a shopping list instead of 'egg' twelve times is like run-length encoding: nothing is lost and you can rebuild the list exactly. Lossy compression is like summarising a long story: shorter, but the dropped details cannot be recovered. The comparison stops working when the list has twelve different items. Writing '1 apple, 1 bread' adds a count to every item and makes the list longer, which is what happens to RLE with few 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.

In the exam

Start by stating the type: lossless means the original can be restored exactly, lossy means data is removed permanently. Then justify the choice for the file: text and program files need lossless because every bit matters; photographs, music and video can use lossy. For RLE, show each run as count and value, e.g. 5W2B. If asked when RLE fails, say it can make the file larger when there are few repeated values, because every run still needs a count.

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