teach-ict.com logo

THE education site for computer science and ICT

2. Run Length Encoding

Run length encoding looks for blocks of repeated data. This repeated data is called a 'run'.

For example, a simple way to store the following colour information is to allocate a byte of storage for every single item.

 

 

 

 

 

 

 

 

 

 

 

For the 10 colours in the image above, you would need 10 bytes of storage space.

But this is wasteful of storage space and it would result in an unnecessarily large file size.

If you take a closer look at the image, you can see that there are 4 identical purple rectangles, one after another. There is a pattern within the information. And we can take advantage of this pattern by declaring how many sequential purple blocks there are in a row, something like this:

 

 

 

4

 

 

 

 

 

The file now contains 8 bytes (1 byte for each block of data). This has resulted in a 20% saving in the file size, without any loss of information.

A software application could read the file and would notice the '4' in it. It would then know that the next item needs to be repeated 4 times. The resulting output would be exactly the same as the original information.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is run length encoding