×
☰ Menu

Run Length Encoding

Run-length encoding (RLE) is the simplest data compression technique. Run-length encoding (RLE) is a method of lossless data compression in which runs of data (sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. This is most useful on data that contains many such runs.


The general idea behind this method is to replace consecutive repeating occurrences of a symbol with one occurrence of the symbol followed by the number of occurrences.


For example, simple graphic images such as icons, line drawings etc.

Example 1: 

Suppose the string is AAAAAAA then Run-length encoding is A7

A is a character and 7 is the number of times appears that string.

Example 2:

If the input string is “WWWWAAADEXXXXXX”, then the Run-length encoding is W4A3D1E1X6.

W is a character and 4 is the number of times appears that string, A is 3 times, D is one times E is one times and X is 6 times appears in string.

Example 3:

If the input string is “AAAABDDDDEAHHHHH” then the Run-length encoding is A4B1D4E1A1H5