LZW (Lempel–Ziv–Welch) is a lossless, dictionary-based compression method. It starts with a small dictionary of single symbols, here the 13 distinct words in the rhyme. As it reads the input, it keeps extending the current phrase while that phrase is already in the dictionary. When it meets a phrase that isn't there, it outputs the code for the longest known phrase and adds the new, longer phrase to the dictionary.
The key exam point is that the full dictionary is never transmitted. The decoder starts with the same initial alphabet and rebuilds the dictionary itself, following the same rules as it reads the codes. Only the starting alphabet and the list of codes need to be sent, which is why the output is smaller than the input.
Step through the encoding panel and notice how repeated phrases like "pease porridge" quickly get their own codes. Then step through the decoding panel to see the receiver reconstruct identical dictionary entries.
Dictionary-based lossless compression, OCR H446 and AQA 7517.
Browse all free Computer Science resources →
Want one-to-one help with this topic? I'm Damian Biasone, a qualified Computer Science teacher with 20 years' experience, tutoring GCSE and A-Level students online.
OCR A-Level (H446) tuitionAQA A-Level (7517) tuition