Input | Output | Comment |
ab | ab | No encoding |
aab | aab | No encoding |
aaab | aaa0b | Expansion :-( |
aaaab | aaa1b | Encoding, but not compression |
aaaaab | aaa2b | Compression |
ab | aaab | The general case |
where ab is a string of consecutive a and is a binary code of a fixed length.
The runs:
aaaabbbbbaaaaaabbbbbbbcccccc
are encoded as:
aaa1 bbb2 aaa3 bbb4 ccc3
where .... is the compression ratio computes as:
(1) |
where is the size of the input (the sequence of symbols) and the size of the output (the code-stream).