From 42aaa04ecdae9febe00868dee9c37ceaf6f2054b Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 2 Jun 2024 20:44:19 +0200 Subject: [PATCH] add rle --- technology/files/RLE.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 technology/files/RLE.md diff --git a/technology/files/RLE.md b/technology/files/RLE.md new file mode 100644 index 0000000..5646ecd --- /dev/null +++ b/technology/files/RLE.md @@ -0,0 +1,40 @@ +--- +obj: concept +wiki: https://en.wikipedia.org/wiki/Run-length_encoding +rev: 2024-05-31 +--- + +# Run-Length Encoding (RLE) +Run-Length Encoding (RLE) is a simple and effective form of data compression where sequences of the same data value (runs) are stored as a single data value and a count. This technique is most efficient when data contains many such runs, making it particularly effective for repetitive data. + +The basic idea of RLE is to reduce the size of repetitive data by replacing sequences of identical elements with a pair that represents the element and the count of its occurrences. The steps involved in RLE are: + +1. **Identify Runs**: Scan the input data to identify consecutive elements that are the same. +2. **Encode Runs**: Replace each run with a pair of values: the repeated element and the length of the run. + +## Example +Consider the input string: + +``` +AAAABBBCCDAA +``` + +The RLE encoding process would work as follows: + +1. Identify runs: `AAAA`, `BBB`, `CC`, `D`, `AA` +2. Encode runs: `4A`, `3B`, `2C`, `1D`, `2A` + +So, the encoded string would be: + +``` +4A3B2C1D2A +``` + +## Advantages and Disadvantages +### Advantages +- **Simplicity**: RLE is straightforward to implement. +- **Efficiency for Repetitive Data**: RLE can significantly reduce the size of data with many runs of the same value. + +### Disadvantages +- **Inefficiency for Non-Repetitive Data**: If the data does not contain many runs, RLE may not compress the data effectively asd could even increase the data size. +- **Fixed Run Length**: The efficiency of RLE depends on the length of runs. For data without significant repetition, other compression methods might be more effective.