The Maths Behind Everyday Life
The story, the formula and a worked example — see exactly where this maths shows up in the world around you.
How zip files shrink text by being lazy about common letters
Give frequent symbols short codes and rare ones long codes — the total shrinks.
Huffman coding, the heart of zip and many formats, assigns shorter codes to characters that appear often and longer codes to rare ones. The weighted average code length drops below the fixed 8 bits per character.
Weight code length by frequency
The average bits per symbol is the sum of each symbol's probability times its code length. Short codes for common symbols pull the average down.
Average code length
A toy alphabet
One symbol at 50%, others rarer.
Beating 8 bits
- 1
Common symbol
Appears half the time, gets a 1-bit code.
- 2
Rare symbols
Get longer codes, but they appear seldom, so the weighted average stays low.
Frequent-means-short is why text compresses well below 8 bits per character.
The formula behind it
Average Code Length
The takeaway
Huffman coding shrinks data by matching code length to frequency. The frequency-weighted average beats fixed-width encoding.