ai-tldr.devAI/TLDR - a real-time tracker of everything shipping in AI. Models, tools, repos, benchmarks. Like Hacker News, for AI.

Run-Length Encoding

The simplest compression technique: condensing repeating sequences efficiently.

Run-Length Encoding (RLE) Explained

Run-Length Encoding (RLE) is one of the simplest and oldest forms of lossless data compression. Its core idea is to reduce the size of repeating sequences of data, often called "runs." Instead of storing each individual data item in a run, RLE stores the data item and the count of its repetitions.

How Does RLE Work?

Imagine you have a sequence of data like: AAAAABBBCCDAA.

RLE would encode this as:

So, the original sequence of 13 characters could be represented more compactly as 5A3B2C1D2A (10 characters in this representation).

Advantages of RLE

Disadvantages of RLE

Common Use Cases

Example

Consider a small black and white bitmap image line represented by WWWWBBWWWBBBBW (W for white pixel, B for black pixel).

Using RLE, this could be encoded as: 4W2B3W4B1W. The original string had 14 characters, while the RLE version has 10 characters.