Understand the purpose of and need for data compression
📦 Data Storage and Compression
Why do we compress data? 🤔
Imagine you have a huge suitcase full of clothes. If you could fold them tightly, you could fit more into the same space, or even fit them into a smaller suitcase. Compression does the same thing for digital data:
- Save storage space – fewer bytes = cheaper hard drives or cloud storage.
- Reduce bandwidth usage – faster downloads and uploads.
- Speed up processing – less data to read/write means quicker programs.
- Lower energy consumption – less I/O means less power.
In the real world, this means you can store more photos on a phone, stream videos faster, and keep your laptop lighter.
Types of Compression
There are two main families of compression algorithms:
- Lossless – you can recover the original data exactly. Think of a zipper that can be opened and closed without losing any teeth.
- Lossy – some data is discarded permanently. Like a photo editor that removes a few pixels to make the file smaller.
Common lossless examples: ZIP, GZIP, PNG. Common lossy examples: JPEG, MP3, MPEG‑4.
How Compression Works (A Simple Analogy)
Think of a text file as a sentence written in a language that uses many repeated words. If you replace each repeated word with a short code, the sentence becomes shorter. That’s the idea behind dictionary‑based compression (e.g., LZW used in GIF).
Mathematically, if we let n be the number of bits before compression and m after, the compression ratio is:
$ \text{Compression Ratio} = \frac{m}{n} $
Values < 1 mean the file got smaller.
Compression Algorithms Overview
| Algorithm | Type | Typical Use |
|---|---|---|
| ZIP | Lossless | General file archives |
| JPEG | Lossy | Images on the web |
| MP3 | Lossy | Audio streaming |
| PNG | Lossless | Web graphics with transparency |
Exam Tips 📌
- Define compression and explain why it is useful.
- Distinguish lossless vs lossy and give one example of each.
- Show how to calculate a compression ratio with a small numeric example.
- Use an analogy (e.g., packing clothes) to illustrate the concept.
- Remember that lossy compression is acceptable when quality loss is imperceptible (e.g., JPEG images).
- Be ready to sketch a simple diagram of a compression/decompression cycle.
Revision
Log in to practice.