1.3 Compression

Bulk view disabled for Guests. View lessons individually.

Data Compression

1. Lossy vs. Lossless Compression

Compression is the process of reducing file size to save storage space and transmission time.

Lossy Compression

Permanently removes "unnecessary" data that the human eye or ear cannot easily detect.

  • Pro: Massive reduction in file size.
  • Con: Quality is lost; file cannot be restored to original.
  • Use: JPEG (images), MP3 (audio), MP4 (video).

Lossless Compression

Uses mathematical algorithms to rewrite data more efficiently without losing a single bit.

  • Pro: Original file can be perfectly reconstructed.
  • Con: Modest reduction in file size.
  • Use: ZIP files, PNG (images), FLAC (audio).

2. Run-Length Encoding (RLE)

RLE is a form of lossless compression that replaces long sequences (runs) of identical data with a single value and a count.

Visualizing RLE: Image Compression

Imagine a row of 10 pixels in a simple graphic:

W
W
W
R
R
B
B
B
B
W
Uncompressed Data: W, W, W, R, R, B, B, B, B, W (10 units)
⬇ RLE Encoding ⬇
3W, 2R, 4B, 1W (4 units)

We reduced 10 data points down to 4 pairs!

When is RLE most effective?

  • High Redundancy: RLE works best on files with many repeating values (e.g., simple icons, logos, or 1-bit black and white documents).
  • Low Entropy: If every pixel in an image is a different color (like a high-detail photograph), RLE can actually make the file larger because it adds a count to every single pixel (e.g., 1B, 1G, 1R...).

3. Other Lossless Techniques

  • Dictionary-Based Encoding: Used in ZIP files. Common words or patterns are added to a "dictionary" and replaced with a short index number in the text.
⚠️ AS-Level Exam Tip: When explaining Lossy compression, use the term Perceptual Encoding. It describes how the software "perceives" which sounds are too high for humans to hear or which colors are too similar for humans to distinguish, then deletes them.