← Making data smaller

Making data smaller: recap

For after the lessons: one card per lesson, to check what you remember. Answer each question in your head or on paper first, then check it. Nothing here is marked.

Compression

1. Run-length encoding

Try firstEncode the row black, black, black, white, white, white, white, white. Why is run-length encoding called lossless?

Check your answer

0, 3, 5. Decompressing gives back exactly the same data.

Compression stores data in fewer numbers, so it takes less space and is quicker to send. Run-length encoding stores the length of each run of the same colour, taking turns from white: 3 white, 4 black, 1 white is 3, 4, 1. A row that starts black begins with 0.

Decoding the codes gives back exactly the same picture, so it is lossless. It saves a lot when there are long runs and nothing (or worse) when the colour changes every pixel.

Four rows and their codes: 3, 4, 1; 0, 8 (it starts black); 8; and a checkerboard row, 1, 1, 1, 1, 1, 1, 1, 1, which saves nothing. 14 numbers instead of 32.
Four rows and their codes: 3, 4, 1; 0, 8 (it starts black); 8; and a checkerboard row, 1, 1, 1, 1, 1, 1, 1, 1, which saves nothing. 14 numbers instead of 32.
Counting runs · Sound on for the voiceover
Open the lesson →

2. Lossy or lossless

Try firstGive one context that needs lossless compression and one where lossy is fine, with a reason for each.

Check your answer

Lossless: a medical scan or spreadsheet, where every value matters. Lossy: streamed music or a shared photo, where a much smaller file matters more than tiny changes.

Lossless compression (PNG, ZIP, run-length encoding) gives back exactly the original data. Lossy compression (JPEG, MP3) throws away detail people are unlikely to notice, such as tiny differences in shade or sound, so files get much smaller, but that detail is gone for good.

Choose by purpose: lossy for streaming music, video calls and shared photos; lossless for text, spreadsheets, medical images and evidence.

A grey picture stored with run-length codes, count × shade. At tolerance 0 it is lossless: 28 numbers instead of 48, and every pixel comes back exactly.
A grey picture stored with run-length codes, count × shade. At tolerance 0 it is lossless: 28 numbers instead of 48, and every pixel comes back exactly.
Throwing away small differences · Sound on for the voiceover
Open the lesson →