SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 1 · Topic 1.1.7

Data Compression
and Encryption

Lossy · Lossless · RLE · Huffman Encoding · Caesar Cipher

CSZone Cambridge International AS & A Level Computer Science 9618
Learning Objectives

By the end of this video you will be able to...

Distinguish between lossy and lossless compression
Describe and apply Run-Length Encoding (RLE)
Describe Huffman encoding and construct a Huffman tree
Explain the Caesar cipher and understand basic encryption concepts
Why Compress Data?

Making Files Smaller

Faster transmission — smaller files send more quickly over a network
Less storage space — more files fit on a drive or server
Reduced bandwidth usage — important for streaming and mobile data
LOSSY COMPRESSION
Permanently removes some data
Cannot restore original exactly
Used by: JPEG, MP3, MPEG
LOSSLESS COMPRESSION
No data is permanently lost
Can restore original exactly
Used by: PNG, ZIP, GIF
Run-Length Encoding (RLE)

Replacing Repetition with Count + Value

RLE stores repeated consecutive values as a (count, value) pair instead of repeating them — a simple and effective lossless technique.
EXAMPLE: PIXEL ROW
Original: W W W W W W B B B W W W W W
RLE: (6,W) (3,B) (5,W)
14 values → 6 values stored
Most effective with images containing large blocks of the same colour (e.g. logos, screenshots)
Less effective for photographs where every pixel is a different colour — can actually increase file size
Huffman Encoding

Variable-Length Codes for Efficiency

Huffman encoding assigns shorter binary codes to more frequent characters and longer codes to rare ones — always lossless.
HOW IT WORKS
1. Count frequency of each character
2. Build a binary tree — least frequent at bottom
3. Assign 0 for left, 1 for right branches
4. Frequent chars get short codes
EXAMPLE
'E' (freq 50) → 0
'A' (freq 25) → 10
'T' (freq 15) → 110
'X' (freq 10) → 111
Encryption — Caesar Cipher

Protecting Data

Encryption transforms data into an unreadable form (ciphertext) so it cannot be understood if intercepted. Only those with the key can decrypt it.
CAESAR CIPHER (SHIFT CIPHER)
Each letter is shifted by a fixed amount (the key).
With key = 3: A→D, B→E, ..., Z→C
HELLO → KHOOR
To decrypt: shift back by the same amount
Plaintext + key → encrypt → Ciphertext
Ciphertext + key → decrypt → Plaintext
Exam Practice

Cambridge-style questions

Question 1
A pixel row contains the following values: R R R R G G R R R R R R. Apply Run-Length Encoding (RLE) to this data and show the compressed representation.
2 marks
✓ MARK SCHEME
1 mark
Correct identification of runs: 4 R, 2 G, 6 R
1 mark
Correct RLE output: (4,R)(2,G)(6,R)
Exam Practice
Question 2
Explain one difference between lossy and lossless compression. Give one example file format for each.
4 marks
✓ MARK SCHEME
1 mark
Lossy: permanently removes data; original cannot be perfectly restored
1 mark
Lossless: no data permanently lost; original can be perfectly restored
1 mark
Lossy example: JPEG / MP3 / MPEG
1 mark
Lossless example: PNG / GIF / ZIP
Common Mistakes

Don't lose easy marks

1
Saying lossy compression "destroys the file" — it reduces quality but the file remains usable. The original exact data cannot be restored, but the compressed version is still a valid image/audio file.
2
Saying RLE is always better — RLE can make files larger if there is little repetition (e.g. a photographic image). Always say it works best for data with long runs of repeated values.
3
Confusing encryption with compression — encryption changes data to hide its meaning (security). Compression changes data to reduce its size (efficiency). They serve different purposes.
4
In Huffman coding, saying "all codes have equal length" — the whole point is that codes are variable length. Frequent characters get shorter codes. Fixed-length codes are not Huffman encoding.
Topic Summary — 1.1.7

What You Need to Know

COMPRESSION TYPES
Lossy: removes data permanently (JPEG, MP3)
Lossless: original perfectly restorable (PNG, ZIP)
RLE: (count, value) pairs for repeated data
Huffman: short codes for frequent chars
RLE
Best for: large blocks of same colour/value
Poor for: photographs, random data
Lossless — original data preserved
Simple and fast to compute
ENCRYPTION
Converts plaintext → ciphertext using a key
Caesar cipher: shift each letter by key value
Only someone with the key can decrypt
Symmetric: same key to encrypt/decrypt
CSZone

Next Video

1.2.1
Communication Methods
Serial · Parallel · Simplex · Duplex · Bandwidth
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools