Squash It
How computers shrink files: why we compress at all, the lossy against lossless trade-off, run-length encoding performed step by step, and the idea behind Huffman coding, where the symbols used most often are given the shortest codes.
Get the method right under pressure
Free interactive practice on the steps that lose marks under exam pressure.
Start revising freeWhat you'll cover
Why squash a file?
Files can be large, and large files take up storage space and are slow to send across a network. Compression makes a file smaller so it needs less space and can be transmitted faster using less bandwidth. There are two broad approaches. Lossy compression throws some detail away for good to make the file much smaller. Lossless compression makes the file smaller with no data lost at all, so the original can be rebuilt exactly. This module covers both, plus two lossless methods you must know: run-length encoding and Huffman coding.
Compression words
Learn these before you sort any method. The exam asks you to choose between the two approaches and to perform run-length encoding.
Lossy against lossless
The first decision in any compression question is which of these two you need. It depends on whether losing some detail is acceptable.
How to choose and squash
To pick a method, ask whether losing detail matters. If a small loss of quality is fine and small size is the priority, choose lossy. If every bit must survive, choose lossless. For a lossless run of repeated values, run-length encoding stores the value and how many times it repeats. For Huffman coding, give the symbols that appear most often the shortest codes, then read each code off the tree to work out the total number of bits.
Match the term to what it does
- lossy
- lossless
- run-length encoding
- Huffman coding
- permanently removes some detail to shrink the file
- shrinks the file with no data lost at all
- stores a run of repeats as a value and a count
- gives the most frequent symbols the shortest codes
Which method for a text file?
A text document must be compressed so that every single character survives exactly. Which approach must you use?
- Lossless, because no data may be lost from text.
- Lossy, because it makes the smallest file.
- Either one works equally well for text.
- Neither, text files cannot be compressed.
Pick the lossless methods
Select the TWO methods that are lossless compression.
- Run-length encoding
- Huffman coding
- Saving a photo as a smaller lower-quality image
- Dropping sounds the ear barely hears from a track
Count the fixed-length bits
A message has 5 characters. Each character is stored using 8 bits of fixed-length ASCII. Multiply the number of characters by the bits each one uses to find the total number of bits. What is the answer?
Order the run-length steps
Put the steps of run-length encoding in order, earliest first.
- Read along the data from the start
- Find a run of the same value repeated
- Store that value once with a count of how many times it repeats
- Move on and repeat until the whole file is encoded
Complete the compression facts
Compression makes a file smaller so it needs less storage and transmits faster. Compression that throws detail away for good is _____, while compression that keeps every bit is _____. A run of repeated values can be stored as a value and a count by _____ encoding. Giving the most frequent symbols the shortest codes is _____ coding.
Match the file to its best method
- a large holiday photo for a website
- a program source-code file
- a music track for a streaming app
- a legal contract that must read exactly
- lossy, since a tiny quality loss will not be noticed
- lossless, since every character must run correctly
- lossy, dropping sounds the ear barely detects
- lossless, since the wording must stay identical
Spot the true compression facts
Tap the TWO statements that are true about data compression.
- Compression lets files transmit faster and use less storage
- Run-length encoding stores repeats as a value and a count
- Lossy compression can always rebuild the exact original
- Compression never makes a file smaller
Choose the compression
Read each case and choose the best compression approach.
- A website needs its large banner photograph to load quickly, and a very small drop in image quality would not be noticed. Which approach fits best?
- A developer must compress a program file so that it still runs perfectly with not a single bit changed. Which approach fits best?
- An image row is stored as the same colour value repeated many times in a row. Which lossless method is the obvious choice?
Explain data compression
Explain why data is compressed and compare lossy with lossless compression, naming a suitable use for each.
- Explain two reasons for compressing a file
- Explain what lossy compression does and give a file type it suits
- Explain what lossless compression does and give a file type it suits
- Explain how run-length encoding shrinks a run of repeated values