Skip to content

9618 · 1.3

Compression — practice questions

Practice and worked examples for 9618 Compression. Short previews only — attempt the full question in MarkScheme against the official scheme.

Worked example 1

A simple 8x4 pixel monochrome (1-bit colour depth) image is represented by the following binary data, where 1 is black and 0 is white. The data is read row by row.

00000000 01111110 01111110 00000000

Apply Run-Length Encoding to this data. Assume the format is (count, value).

Show solution outline
  1. Analyse the data stream: First, we read the pixels as a single stream: 00000000011111100111111000000000
  2. Identify the runs:
    • The first run is nine 0s.
    • The next run is six 1s.
    • The next run is two 0s.
    • The next run is six 1s.
    • The final run is nine 0s.
  3. Apply RLE: We represent each run with its count and value.
    • (9, 0)
    • (6, 1)
    • (2, 0)
    • (6, 1)
    • (9, 0)
  4. Final Encoded Data: The RLE representation is (9,0)(6,1)(2,0)(6,1)(9,0). The original data required 32 bits (8x4x1). The RLE representation uses 5 pairs of numbers. The exact size would depend on how many bits are used for the count and value, but the number of data items has been reduced from 32 to 10.

Worked example 2

An uncompressed digital photograph has dimensions of 4000 x 3000 pixels and uses a 24-bit colour depth.

(a) Calculate the file size of the uncompressed image in mebibytes (MiB). (b) The image is compressed into a JPEG file of size 4 MB. Calculate the compression ratio.

Show solution outline

Part (a): Calculate uncompressed file size

  1. Calculate total pixels: TotalPixels=4000×3000=12,000,000pixelsTotal Pixels = 4000 \times 3000 = 12,000,000 pixels
  2. Calculate size in bits: Size(bits)=TotalPixels×ColourDepthSize (bits) = Total Pixels \times Colour Depth Size(bits)=12,000,000×24=288,000,000bitsSize (bits) = 12,000,000 \times 24 = 288,000,000 bits
  3. Convert bits to bytes: (1 byte = 8 bits) Size(bytes)=288,000,000/8=36,000,000bytesSize (bytes) = 288,000,000 / 8 = 36,000,000 bytes
  4. Convert bytes to mebibytes (MiB): (1 MiB = 1024 KiB = 1024 × 1024 bytes) Size(MiB)=36,000,000/(1024×1024)Size (MiB) = 36,000,000 / (1024 \times 1024) Size (MiB) ≈ 34.33 MiB

Part (b): Calculate compression ratio

  1. Ensure units are consistent: The question gives the compressed size in megabytes (MB) and we calculated in mebibytes (MiB). For exam purposes, often the distinction is ignored, but it's good practice to be consistent. Let's assume the question implies MB (1,000,000 bytes) for the compressed size and we should use the same for the uncompressed size for a fair comparison. Uncompressedsize(MB)=36,000,000/1,000,000=36MBUncompressed size (MB) = 36,000,000 / 1,000,000 = 36 MB Compressedsize(MB)=4MBCompressed size (MB) = 4 MB
  2. Calculate the ratio: CompressionRatio=UncompressedSize/CompressedSizeCompression Ratio = Uncompressed Size / Compressed Size CompressionRatio=36MB/4MB=9Compression Ratio = 36 MB / 4 MB = 9
  3. State the answer: The compression ratio is 9:1.