Run-Length Encoding (RLE) is a simple lossless compression technique that replaces sequences of identical data elements (runs) with a single data value and a count of how many times it repeats. For example, the string 'AAAAABBB' would be stored as '5A3B'.
In binary RLE, the representation consists of a fixed-size binary count followed by the data value. If using 8 bits for the count, the number 4 would be stored as , followed by the ASCII or binary code for the character or pixel color.
RLE is highly effective for data with many consecutive identical values, such as simple icons, line drawings, or documents with large areas of white space, but it can actually increase file size if the data has no repeating patterns.
Choosing between lossy and lossless compression depends on the required fidelity and the available storage or bandwidth.
| Feature | Lossy Compression | Lossless Compression |
|---|---|---|
| Reversibility | Irreversible (Data lost) | Reversible (Original restored) |
| File Size | Very small | Moderately reduced |
| Quality | Reduced (Degradation) | Identical to original |
| Use Case | Photos, Video, Audio | Text, Code, Spreadsheets |
Identify the Data Type: If an exam question asks which compression to use for a spreadsheet or a program, always choose lossless. If it involves streaming video or background music, lossy is usually the correct answer.
RLE Calculations: When calculating RLE savings, remember to account for the size of the 'count' byte. If the original data is 100 bits and the RLE version uses 20 bits, the saving is bits (an reduction).
Terminology Precision: Use terms like 'perceptual shaping' for audio and 'irreversible' for lossy compression to gain full marks in descriptive questions.
Check for Patterns: Before suggesting RLE, look at the data. If the data is 'ABCABC', RLE would result in '1A1B1C1A1B1C', which is longer than the original; in this case, RLE is inefficient.