Show understanding of the need for and examples of the use of compression

1.3 Compression

Why Do We Need Compression? 📦

Imagine you have a huge backpack full of books, clothes and gadgets. If you want to travel, you’d want to pack it as tightly as possible to save space and reduce weight. In the digital world, files can be huge too – images, videos, documents, and even simple text files. Compression is the digital equivalent of packing: it reduces the file size so it can be stored, transmitted, and processed more efficiently.

Types of Compression

  • Lossless – No data is lost. Think of a reusable shopping bag that you can refill again and again. Examples: ZIP, RAR, PNG, FLAC.
  • Lossy – Some data is discarded to achieve higher compression. Like a photo taken with a lower resolution to save space. Examples: JPEG, MP3, MP4.

Compression Ratio Formula

The compression ratio tells us how much smaller the compressed file is compared to the original: $$ \text{Compression Ratio} = \frac{\text{Size}_{\text{original}}}{\text{Size}_{\text{compressed}}} $$ If the ratio is 2:1, the compressed file is half the size of the original.

Real‑World Examples

  1. ZIP (Lossless) – Used for compressing documents, code, and backups.
    Analogy: Packing a stack of books into a single suitcase without breaking any pages.
  2. JPEG (Lossy) – Common for photographs.
    Analogy: Taking a high‑resolution photo and then removing some background details that the eye rarely notices.
  3. MP3 (Lossy) – Audio compression for music.
    Analogy: Removing background hum from a song so you only hear the main instruments.
  4. PNG (Lossless) – Images with transparency, like icons.
    Analogy: Storing a picture exactly as it is, but squeezing it into a smaller box.

Compression in Action – A Quick Demo

Let’s look at a simple example: a 5 MB text file compressed to 1 MB using ZIP.

File Type Original Size Compressed Size Compression Ratio
Text Document 5 MB 1 MB 5:1

When to Use Which?

  • Use lossless when you need to preserve every bit of data – e.g., source code, legal documents.
  • Use lossy when you can sacrifice a little quality for a lot of space – e.g., streaming music, online video.

Key Takeaways 🎓

  • Compression saves storage and bandwidth.
  • Lossless keeps data intact; lossy reduces quality.
  • Choose the right algorithm based on the file type and required fidelity.
  • Compression ratio helps compare effectiveness.

Revision

Log in to practice.

2 views 0 suggestions