Show understanding of how a text file, bitmap image, vector graphic and sound file can be compressed, and be able to choose an appropriate method for a given situation.
.txt research papers can be reduced to ≈ 150 MB with ZIP, saving storage without any loss of information.Use the checklist below to decide which technique is appropriate. The final column indicates the relevant Cambridge Assessment Objectives (AO).
| Question | Guidance | Typical methods | AO(s) addressed |
|---|---|---|---|
| Is the original data required to be reproduced exactly? |
| Lossless: ZIP, PNG, FLAC, SVG + GZIP. Lossy: JPEG, MP3, AAC. | AO1 – recall facts; AO2 – analyse suitability. |
| What type of data are you compressing? |
| See detailed sections below. | AO1, AO2. |
| Do you need to balance size against quality? | Adjust quality parameters (JPEG quality factor, MP3 bitrate, etc.) to reach the desired trade‑off. | Quality sliders, variable‑bit‑rate (VBR) modes. | AO2, AO3 – evaluate trade‑offs and justify choices. |
Store sequences of characters (e.g., source code, documents). Redundancy appears as repeated characters, common words, and recurring substrings.
Example: AAAAABBBCC → 5A3B2C
Rarely used for plain text because any loss changes meaning. In specialised contexts (e.g., speech‑to‑text transcripts) lossy text compression may be acceptable, but it is not part of the Cambridge syllabus.
Exploit statistical frequency and repeated patterns to replace them with shorter codes.
Text: ABABABAA → frequencies: A = 5, B = 3.
Huffman tree gives codes: A → 0, B → 1.
Compressed bit‑stream: 01010100 (8 bits) instead of 8 × 8 = 64 bits in ASCII.
Store colour information for each pixel. Uncompressed size = width × height × bits‑per‑pixel.
| 52 55 |
| 53 54 |
After padding to an 8 × 8 block and applying the DCT, the top‑left coefficient (the average) is ≈ 52, while the remaining 63 coefficients are close to 0. Quantisation rounds the small coefficients to 0, leaving only a few non‑zero values to be Huffman‑encoded – a dramatic size reduction.
Describe images with geometric primitives (lines, curves, shapes) and their attributes. File size depends on the number of objects, not on pixel count, giving inherent resolution‑independence.
Usually unnecessary because vectors store mathematical definitions. If a vector is rasterised for a specific purpose, the resulting raster can be compressed with lossy image formats.
Compress the descriptive text (remove whitespace, shorten attribute names) and any numeric data using standard lossless compressors.
Original SVG snippet (≈ 120 bytes):
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="black" fill="red"/>
</svg>
After GZIP compression the same graphic occupies ≈ 45 bytes – a 62 % reduction.
Store audio as a series of amplitude samples taken at a fixed sampling rate (e.g., 44.1 kHz) and bit depth (e.g., 16‑bit). Redundancy exists because successive samples are often similar.
Original PCM samples (16‑bit): 1000, 1012, 1025, 1030, 1020 …
Predict each sample as the previous value. Prediction errors: 0, 12, 13, 5, ‑10 …
These small errors are entropy‑coded, giving roughly a 2:1 compression on typical music.
| File type | Typical formats | Lossless method(s) | Lossy method(s) | Key idea | AO(s) |
|---|---|---|---|---|---|
| Text | .txt, .csv | RLE, Huffman, LZW (ZIP) | – (rarely used) | Exploit character frequency and repeated substrings. | AO1, AO2 |
| Bitmap image | .bmp, .png, .gif, .jpg | PNG (filter + deflate), GIF (LZW), BMP + RLE | JPEG (DCT + quantisation + Huffman) | Transform spatial redundancy (DCT) or encode exact repetitions. | AO1, AO2, AO3 |
| Vector graphic | .svg, .pdf | SVG + GZIP (deflate), PDF filters (Flate, LZW) | – (normally lossless) | Compress descriptive text; no pixel data to discard. | AO1, AO2 |
| Sound | .wav, .flac, .wavpack, .mp3, .aac | FLAC, WavPack, ALAC (predictive + Rice) | MP3, AAC (sub‑band transform + psychoacoustic masking + Huffman) | Predictive coding for redundancy; discard inaudible frequencies for lossy. | AO1, AO2, AO3 |
The entropy of a source with symbol probabilities \(p_i\) is
\(H = -\sumi pi \log2 pi\) bits per symbol.
No lossless code can, on average, use fewer than \(H\) bits per symbol. Huffman coding approaches this limit when symbol probabilities are powers of ½.
\(F(u,v)=\frac{1}{4}\alpha(u)\alpha(v)\sum{x=0}^{7}\sum{y=0}^{7} f(x,y)\cos\frac{(2x+1)u\pi}{16}\cos\frac{(2y+1)v\pi}{16}\)
where \(\alpha(0)=\frac{1}{\sqrt{2}}\) and \(\alpha(k)=1\) for \(k>0\).
The encoder builds a masking‑threshold curve based on the ear’s sensitivity. Any spectral component below this curve is considered inaudible and can be quantised more coarsely or discarded, yielding high compression with little perceived loss.
| Exam command word | Relevant note section | Suggested answer points |
|---|---|---|
| Define | 2.1 – 2.4 (e.g., “Define lossless compression.”) | Lossless = exact reconstruction; lossy = acceptable loss of detail. |
| Explain | Key ideas for each file type | State the principle (e.g., “JPEG uses DCT to separate low‑ and high‑frequency components.”) |
| Compare | Comparison summary table | Contrast PNG (lossless) with JPEG (lossy) in terms of size, quality, typical use. |
| Evaluate | Decision guide & quality‑trade‑off discussion | Discuss how a lower JPEG quality reduces size but may introduce blocking artefacts; weigh against storage constraints. |
main method, functions for reading, compressing, and writing files, and comments describing each step.Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.