← Teacher guides

Teacher guide: Making data smaller

Compression for Years 9–10: why it matters, run-length encoding (store how many of each colour in turn, and get back exactly the same picture), and lossy compression, which throws away what we won't notice, for good.

Open the student course · How the ideas build

Each lesson works two ways. Students can work through the online tutorial at their own pace (it checks their answers and saves their progress in their browser), or you can teach it to the whole class from the slides, then send students into the tutorial for the Modify and Make steps.

Every lesson guide has plain-language notes, the answers to every check, a solution for every task, and slides and a worksheet for Waypoints Prepare. These guide pages are not linked from student pages, but they are not secret either: keep printed Teacher editions for answers you do not want students to find.

Whole-course cheat sheet: Open to print (every command, grouped by unit: a handout for the final challenge)

Compression

Run-length encoding, and when it is fine to throw data away (lossy and lossless).

Compression in 5 minutes (read before teaching this unit)

The idea in plain words

Data is big: a phone photo is tens of millions of numbers. Compression stores the same data in fewer numbers, so it takes less space and less time to send.

Run-length encoding (RLE) stores runs: instead of white, white, white, black, black, black, black, white, store 3, 4, 1 (how many of each colour in turn). Decompressing gives back exactly the same picture, so RLE is lossless. It works well when data has long runs (icons, diagrams, faxes) and badly when every value differs (a checkerboard, a photo, noise), where it can even make data bigger.

Lossy compression throws away detail people are unlikely to notice: here, shades close to each other are treated as the same, so runs get longer. The data gets much smaller, but what is thrown away is gone for good. JPEG and MP3 are lossy; PNG and ZIP are lossless.

Why it matters

Choosing the wrong kind has consequences: a lossy medical scan, legal photo or spreadsheet could change what someone sees or decides. Streaming music and photos online is only practical because of lossy compression.

What students get wrong

  • Forgetting where the runs start. A row that starts black needs a 0 first (no whites).
  • Thinking compression always saves space. Data with no runs can get bigger.
  • Thinking lost detail can be recovered. Once a lossy file is saved, the original values are gone.

Where it comes from

The pixel codes are CS Unplugged's Image representation activity (csunplugged.org, CC BY-SA 4.0).

The words

compression, run-length encoding, lossless, lossy, compression ratio, tolerance.

Cheat sheet: Open to print (A4, with board pictures) · Open in Print · Markdown

Project briefs

Printable task sheets for assessment or extension: students make something, hand it in and explain their choices. The success criteria are the curriculum nodes' own. Open the briefs page

Squash it and see (after lossy-lossless)

A club wants to share a lot of files without using up its storage or its internet. Your job is to find out what compression really does, and to say when it is safe to use.

Take one image and one text document your teacher approves. Save each in at least two ways, one that keeps everything and one that throws some away. Compare the file sizes and look closely at what changed. Then compress a short row of pixels by hand using run-length encoding, and have a partner rebuild it.

Hand in:

  • A table of file sizes: each file, each format, and its size, with a note on which formats keep everything and which do not.
  • Close-up pictures or a description of what changed in the image when information was thrown away.
  • A row of at least 20 pixels you designed, its run-length encoding, and your partner's rebuilt row next to the original.
  • A short explanation: one real reason file size matters, which of your files you would compress each way and why, and one thing that could go wrong if the wrong kind of compression were used.

Evidences:

  • Why compression is needed (AC9TDI10K03 node 1): Correctly explains what compression does (reduces file size); Gives at least one concrete reason why reducing file size matters
  • Lossless compression — run-length encoding (AC9TDI10K03 node 2): Correctly applies RLE to encode a simple sequence; Explains how the encoded form represents the original data
  • Lossy vs lossless — trade-offs and consequences (AC9TDI10K03 node 3): Correctly distinguishes lossless (exact recovery) from lossy (permanent data loss) compression; Identifies an appropriate context for each type and justifies the choice; Names at least one consequence of using lossy compression in an inappropriate context

Agree the files and the tools first. PNG, GIF, ZIP and similar keep everything; JPEG at lower quality throws information away. Exact sizes will differ between tools, which is fine: the pattern is the evidence. A photo usually shrinks well with JPEG and little with PNG, while a simple drawing with large areas of one colour does the opposite. Let students zoom in on a heavily compressed JPEG to see blocks and smudges.

For the explanation, strong answers match context to type: a bank statement, a program or a marked spreadsheet must come back exactly, so lossless; a holiday photo or a song usually does not need to. The consequence of getting it wrong is concrete, for example a number in a scanned document that is no longer readable. Check the run-length row: students sometimes encode the length without the value, or lose which colour comes first.