1

mrahmedcomputing

KS3, GCSE, A-Level Computing Resources

Lesson 8. Compression


Lesson Objective

  1. Understand the purpose of compression.
  2. Be able to explain the differences between lossy and lossless compression.
  3. Carry out Run Length Encoding and use Huffman Coding to compress text.

Lesson Notes

Compression?

Compression is a technique used to reduce the size of digital files, making them more manageable for storage and transmission.

Lossy and Lossless Compression

There are 2 types of compression you need to be aware of.

Lossy Compression: By using this type of compression, some data is permanently removed from the original file, resulting in a smaller file size. For example, by reducing the color depth of an image, shades of colors are averaged, leading to a smaller file. JPEG format uses lossy compression.
By using Lossy compression, some quality is sacrificed in favor of smaller file sizes.

Lossless Compression: With lossless compression, files are reduced in size without any loss of data. It is ideal for files where data integrity is crucial, such as text, spreadsheets, and financial records. However, lossless compression typically doesn't achieve the same level of reduction as lossy methods. Various lossless standards exist, ensuring that files can be restored to their original quality.

In summary, lossy compression prioritizes smaller sizes at the cost of quality, whereas lossless compression maintains data integrity without sacrificing quality .


Run Length Encoding (AQA Exam Only!!)

Run-length encoding (RLE) is a form of lossless data compression. RLE aims to reduce file size while preserving data integrity. It is commonly used for simple graphic images, such as icons, line drawings, and animations. In RLE, runs of data (sequences where the same value occurs consecutively) are stored as a single data value along with a count. Instead of representing each run individually, RLE condenses them into a more compact format.

Imagine a screen with plain black text on a white background.
The scan line might look like this:
WWWWWWWWBWWWWWWWBBBWWWWWWWWWWWWWBBWWWWWW.
By applying RLE, it becomes: 8W1B7W3B13W2B6W.
This represents the original 67 characters in only 18.

00000000000001000000000000111000000000000000000000000100000000000000

130 11 120 31 240 11 140


Huffman Coding (AQA Exam Only!!)

Lossless compression algorithm that is used to compress text. Watch the video on the right. It explains how text can be compressed using Huffman Coding.


Benefits of Compression

3