itslabtime.com

Information · Computing · Data Representation

Lossless compression and information entropy

Compression utilizes the repetition or differences in frequency within data to represent it with fewer symbols. However, no single method can always reduce all inputs to a smaller size.

Related experiment: Data compression →
Data compression
Data compression: simulation view →

Meaning and mechanism

Lossless compression must be able to restore the original data exactly from the compressed representation. RunLength encoding utilizes continuous repetition, while Huffman encoding utilizes differences in the frequency of symbols.

It is important to assign short codes to frequently occurring symbols, but these codes must not create ambiguity. Using run lengths for data with infrequent repetition can increase size due to the frequency information.

Relationships and conditions

Entropy H is a reference for the ideal average information content of a symbol distribution. In binary Huffman coding with multiple symbols, the average code length L can be compared with H≤L<H+1.

The experiment excludes the use of a limited alphabet and a fixed number of original bits, and excludes the storage cost of Huffman tables. In actual files, header and dictionary costs, as well as block costs, must also be included.

What to observe in the simulation

Repetition and symbol frequencies determine compression efficiency.

Inputs use four symbols. Originals use 8 bits per symbol; RLE uses 8-bit symbol and count. Huffman table overhead is excluded.

Key relationships and symbols

H ≤ L < H + 1 · ratio = compressed / original

Symbols and units used in the formulas
SymbolMeaningUnit
HInformation entropy per symbolbit/symbol
LAverage code lengthbit/symbol
Compression ratiocompressed size/original sizeDimensionless

Worked example

How are frequent symbols coded in Huffman?

Usually shorter · Repetition and symbol frequencies determine compression efficiency.

Common misconceptions

  • The fact that the code itself has become smaller does not mean that the entire actual saved file has decreased by the same proportion.

Explore this concept through experiments

References

OpenStax · Introduction to Computer Science (English)