Lossless Data Compression
Part of: Data
Making Data Smaller Data compression reduces the number of bits needed to store or transmit information. Smaller data loads faster, costs less to store, and saves bandwidth. There are two families of compression: lossless and lossy. This lesson covers lossless compression . Lossless Means Reversible In lossless compression , every bit of the original data can be perfectly reconstructed after decompression. Nothing is thrown away. It is ideal for text, code, and spreadsheets, where losing even one character would corrupt the file. Formats like ZIP and PNG use lossless methods. Run-Length Encoding A simple lossless technique is run-length encoding (RLE) . It replaces a run of repeated characters with the character followed by a count. The string AAAB becomes A3B1. Because the rule is exact, you can always rebuild the original. For AAAB, this prints A3B1. For WWWWWWB, it prints W6B1. Trade-Offs - Strength : perfect reconstruction, so no information is ever lost. - Limit : the size reduction depends on the data. Highly repetitive data compresses a lot; random data may not shrink at all and can even grow. Run-length encoding is most effective when data has long runs of repeated values,
Challenge: Run-Length Encode