GCSE Computer Science · public explanation

Data Compression

Compare lossy and lossless compression for GCSE Computer Science. Follow run-length encoding and Huffman examples with guidance on exam-board scope.

Read the explanation and worked examples, then choose your exam board to continue with activities and practice in your account.

OCR J277On the specificationOCR J277 1.2.5

The need for compression, lossy/lossless characteristics and their effects; no required Huffman/RLE execution.

AQA 8525 (2027+)On the specificationAQA 8525 3.3.8

Lossy/lossless, run-length encoding and Huffman trees, encoding, decoding and size calculations.

Use fewer bits to represent the data

Compression reduces the number of bits required to store or transmit a representation. Smaller files need less storage and, at the same transfer rate, less time to send. Encoding and decoding can require processing.

Lossless compression allows the exact original data to be reconstructed. Lossy compression permanently removes some information, often information people are less likely to notice. Decompressing a lossy file does not restore what was discarded.

NeedSuitable approachReason
Program source or important textLosslessEvery original character must survive
Small music downloadLossy may be suitableSome sound detail may be sacrificed for a smaller file
Image needed for exact scientific measurementsLosslessOriginal pixel values must be preserved

AQA focus

AQA: run-length encoding stores a value and its run length

Run-length encoding (RLE) replaces consecutive repeats with a count and the repeated value. Follow the supplied format: in this example the count comes first. A new run starts when the value changes, even if the earlier value appears again later.

Encode AAAABBBCCDAA

  1. Four A characters form the first run: 4A.
  2. Then three B, two C, one D and two A: 3B 2C 1D 2A.
  3. Combined representation: 4A3B2C1D2A.
  4. Decoding the counts restores AAAABBBCCDAA exactly.

The two A characters at the end cannot be merged with the first run: order matters.

AQA focus

AQA: connect symbol frequencies to Huffman tree paths

Huffman coding gives variable-length bit codes to symbols. Frequently occurring symbols can receive shorter codes. One way to understand the tree is to repeatedly combine its two lowest-frequency nodes. If frequencies tie, more than one valid tree can exist; always use the tree supplied by the question.

Label the two branches from each node 0 and 1. A symbol's code is the complete route from the root to its leaf. No symbol's code is the beginning of another symbol's code, so the bit stream can be decoded without separators.

Frequencies A:5, B:2, C:1, D:1

  1. Combine C:1 and D:1 to make node CD:2.
  2. Combine B:2 and CD:2 to make node BCD:4.
  3. Combine BCD:4 and A:5 to make the root:9.
  4. One valid labelled tree gives A=1, B=00, C=010 and D=011.

The more frequent A uses one bit; the less frequent C and D use three each.

OCR focus

OCR: justify lossy or lossless for the user's needs

OCR J277 requires the need for compression and the characteristics and effects of lossy and lossless methods; it does not require constructing a Huffman tree or executing RLE. Focus your answer on retained information, suitability, size and the consequence for this user.

Send a photograph and an executable program

  1. The photograph may use lossy compression if some loss of visible detail is acceptable.
  2. The executable must preserve every original bit, so use a lossless method.
  3. Both may transfer faster if compressed size is smaller; their tolerance for lost information differs.

‘Lossy is always better because it is smaller’ ignores what the file is for.

Continue with your exam board

The course combines lesson videos, interactive activities, topic questions and original exam mocks. Sign in to use the learning tools and save your progress; your account’s course access applies.

Independent learning resources. Not endorsed by AQA or OCR. These public introductions complement the full course and the official specification.