add rle
This commit is contained in:
parent
2f3f94c40f
commit
42aaa04ecd
1 changed files with 40 additions and 0 deletions
40
technology/files/RLE.md
Normal file
40
technology/files/RLE.md
Normal file
|
@ -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.
|
Loading…
Reference in a new issue