Advanced
Run-Length Encoding
The simplest lossless compression technique.
Time Complexity
O(N)
Space Complexity
O(1)
Interactive Visualization
Technical Guide
Run-Length Encoding (RLE) is the simplest form of data compression. it replaces consecutive identical characters (a 'run') with a single character and its repeat count. For example, 'AAAAA' becomes 'A5'. It is highly effective for data with long runs of identical values, such as simple icons or sparse datasets.
Logical Phases
- 1Scanning the string from left to right.
- 2Counting consecutive identical characters.
- 3Writing the character followed by the count to the output.
- 4Handling runs of length 1 (which might increase size).
Implementation
result += char + count;Expert Pitfalls
Using RLE on high-entropy text (like 'ABCDEFG') which will double the storage size.