Computing

Why common letters get short codes in a ZIP file: Huffman coding

A binary tree with the letters i, s and p near the top with two-bit codes and rare letters m, v and r deeper down
30seconds
The 30-second version

ASCII spends 8 bits on every letter, whether it is a common e or a rare z. In 1951 a graduate student, David Huffman, found a way to give frequent symbols short codes and rare ones long codes, with a tree you build from the bottom up.

Type your own message, merge the two lightest symbols one step at a time, and watch the codes appear and the bit count fall. Then see why the method is optimal for whole-bit codes and where it still hides, from ZIP and PNG files to JPEG and MP3.

Deep dive · 4 min
Deep dive · 4 min

More in Computing

View all →