3 ms·
>For a large enough amount of data, that can save me enough space to include a program that can print the decompressed string in less space than the original st
by dTal 7y ago
>For a large enough amount of data, that can save me enough space to include a program that can print the decompressed string in less space than the original string
It can't. You'll find that, in a truly random sequence, the "compressible substrings" will be infrequent enough that you will use up your data budget just specifying where they go.
Let's take your run-length example. Let's work in bits to make it simple. Your chain of 10 zeros - 10 bits of information - happens on average every 2^10 bits. Let's say we magically compress this sequence down to 0 bits - we just assume that statistically it's in there somewhere, so we don't need to store it. All that's left is to specify where it goes! How many bits do we need for that? Well... the sequence occurs on average every 2^10 bits. We need all 10 of the saved bits just to say where the sequence goes! We haven't saved anything!
The more compressible the substring, the less frequent it is, and the more information is required to specify its location. This is also why we can't compress files by specifying their offset in the digits of pi, incidentally.