SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
AQA 8525 · Section 3.3 · 3.3.8a

Lossless
Compression

Run-Length Encoding · Dictionary Coding · No Data Lost

CSZoneAQA GCSE Computer Science 8525
Why Compress?

Reducing File Size

Compression reduces file size so files take less storage space and can be transmitted faster over a network. Lossless compression reduces size without losing any data — the original file can be perfectly reconstructed.
Used for: text files, source code, databases, PNG images, ZIP archives
The decompressed file is identical to the original — no data is ever lost
Essential when exact data matters — e.g. medical records, financial data, executable programs
Run-Length Encoding (RLE)

Counting Repeating Values

RLE replaces consecutive repeated values with a count and value pair. Highly effective for data with long runs of the same value (e.g. simple images).
Original: WWWWWWBBBWWWWBBWWWWWWWW
RLE: 6W 3B 4W 2B 8W

Original: 23 characters
RLE: 10 characters → compressed by 57%

Image row: ■■■■■□□□□■■■ (12 pixels)
RLE: 5■ 4□ 3■ (6 values)
Dictionary Coding

Replacing Repeated Patterns

Dictionary coding (used in ZIP, LZ77, LZW) builds a dictionary of repeated patterns during compression. Repeated phrases are replaced with short codes. Common in text and source code.
Original text:
"the cat sat on the mat near the hat"

Dictionary entry: [01] = "the "

Compressed:
"[01]cat sat on [01]mat near [01]hat"

Each occurrence of "the " is replaced with a 2-byte code.
Exam Practice

Have a go at this question

AQA-style question
The following image row is to be compressed using Run-Length Encoding: ■■■■□□■■■■■□□□□
(a) Write the RLE representation.
(b) How many values has RLE reduced it from and to?
3 marks
(a) 4■ 2□ 5■ 4□ [2]
(b) 15 values → 8 values [1]
Key Takeaways

What to Remember

Lossless compression — reduces size, original can be perfectly reconstructed
RLE — replaces runs of repeated values with count + value
Dictionary coding — replaces repeated phrases with short codes
Used for: text, programs, medical/financial data — any file where exact reproduction is required