Show understanding of lossy and lossless compression and justify the use of a method in a given situation

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – Compression

1.3 Compression

Learning Objective

Show understanding of lossy and lossless compression and justify the use of a method in a given situation.

What is Compression?

Compression is the process of reducing the number of bits required to represent data. It exploits redundancy or perceptual limitations to store or transmit information more efficiently.

Types of Compression

  • Lossless compression – original data can be perfectly reconstructed.
  • Lossy compression – some information is permanently discarded; reconstruction is an approximation.

Lossless Compression

Used when exact data recovery is essential (e.g., text files, executable programs, medical images).

Common techniques:

  1. Run‑Length Encoding (RLE)
  2. Huffman coding
  3. Lempel‑Ziv‑Welch (LZW)

Example – Huffman coding:

Given symbol probabilities \$p_i\$, the optimal average code length is bounded by the entropy:

\$H = -\sum{i=1}^{n} pi \log2 pi\$

Suggested diagram: Huffman tree for symbols A, B, C, D with frequencies 45, 13, 12, 30.

Lossy Compression

Used when a perfect replica is not required and higher compression ratios are desired (e.g., audio, video, photographs).

Common techniques:

  1. Transform coding (e.g., Discrete Cosine Transform in JPEG)
  2. Quantisation of frequency components
  3. Perceptual coding (e.g., MP3 for audio)

Example – JPEG compression steps:

  • Convert image to YCbCr colour space.
  • Divide into \$8\times8\$ blocks and apply DCT.
  • Quantise DCT coefficients using a quantisation matrix.
  • Encode using run‑length and Huffman coding.

Comparison of Lossless and Lossy Methods

AspectLosslessLossy
Data integrityExact reconstructionApproximate reconstruction
Typical applicationsText, source code, archives, medical imagingPhotographs, audio, video streaming
Common algorithmsRLE, Huffman, LZW, DEFLATEJPEG, MP3, MPEG, AAC
Compression ratioUsually 2:1 – 3:1Often 10:1 – 100:1 or higher
Impact on qualityNo loss of qualityQuality degrades with higher compression

Justifying the Choice of Compression Method

When selecting a compression technique, consider the following factors:

  • Purpose of the data – Is exact fidelity required?
  • Storage or bandwidth constraints – How much reduction is needed?
  • Processing resources – Can the system handle complex encoding/decoding?
  • Acceptable loss of quality – What level of artefacts is tolerable?

Case Studies

Case Study 1: Archiving Legal Documents

Legal documents must retain every character exactly as originally written. A lossless method such as ZIP (DEFLATE) is appropriate, providing a moderate reduction while guaranteeing perfect recovery.

Case Study 2: Streaming a Sports Event

Live video requires high compression to fit limited bandwidth. A lossy codec like H.264 (MPEG‑4 A \cdot C) is justified because viewers accept minor artefacts, and the priority is low latency and smooth playback.

Case Study 3: Storing MRI Scans

Medical imaging demands diagnostic accuracy. Lossless compression (e.g., JPEG‑2000 lossless mode) preserves pixel values exactly, ensuring no diagnostic information is lost.

Key Points to Remember

  • Lossless = no data loss; suitable for text, code, critical images.
  • Lossy = data loss; suitable for media where human perception can tolerate approximations.
  • Choose the method that balances storage/bandwidth limits with the required data fidelity.