Tutorials Developer

David Huffman: An Optimal Code, Written to Avoid an Exam

Profile ยท ~15 min
Historical photograph of David A. Huffman.Archival scan, shown at its original size. Image credit & licence

Overview

David Albert Huffman (1925โ€“1999) derived Huffman coding in 1952 as an MIT graduate student, when his professor offered the class a choice between a final exam and a term paper on finding the most efficient prefix-free code. He solved it, producing a construction that is provably optimal โ€” and better than the Shannon-Fano method his professor had co-devised.

What You Need

  • Lived: 1925โ€“1999, United States
  • Anchor year: 1952 โ€” Huffman coding
  • Strand: overlooked โ€” everyone uses it, nobody names it

Steps

1

The problem as it stood

Shannon had shown entropy bounds compression, but constructing an actual optimal code was open. Shannon-Fano coding worked top-down and was good but not provably optimal.

2

What he actually did

Huffman inverted the approach: build the code tree bottom-up, repeatedly combining the two least frequent symbols into a node whose frequency is their sum, until one tree remains. Read off the paths and you have the code. He proved it optimal for symbol-by-symbol coding.

3

How it worked

Frequent symbols end up near the root and get short codes; rare ones sit deep and get long ones. Because it is a tree, no code is a prefix of another, so a stream decodes unambiguously without separators. The bottom-up construction is what makes optimality provable, and it is why the top-down method fails.

4

What it made possible

Huffman coding is inside JPEG, MP3, PNG, ZIP, MPEG and countless other formats โ€” usually as the final entropy-coding stage after a transform has done the perceptual work. It has been in continuous use for over seventy years.

5

What happened to him

He taught at MIT and then founded the computer science department at UC Santa Cruz. He was also a serious mathematical origami practitioner. He did not patent the coding scheme.

6

Where the credit landed

Huffman's name is attached to the algorithm and known to every compression engineer, which makes him better credited than most in this wave. He did not patent it, and it entered universal use free of licensing โ€” a contrast worth noting against the MP3 patent history a few entries along.

Pro Tips

  • Bottom-up construction is what makes it provably optimal; the top-down method is not.
  • Prefix-free means no separators are needed between codes.
  • He never patented it, which is part of why it is everywhere.

What You'll Learn

The last stage of almost every codec is a seventy-year-old term paper.

Where Huffman sits in a codec

A modern codec has stages. A transform such as the DCT concentrates energy into few coefficients; quantisation discards perceptually unimportant precision โ€” this is where the loss happens; then entropy coding packs the result losslessly, and that stage is usually Huffman or arithmetic coding. Huffman is doing no perceptual work at all: it is squeezing the last redundancy out of whatever the earlier stages left.

Where This Fits

This guide covers one specific part of the history of media technology. The wider picture โ€” how each link in the chain from capture through transmission to display was actually built, who built it, and why the credit so often landed somewhere else โ€” is in A History of Broadcast Technology: The Chain From Capture to Screen, which frames the discipline as a whole and links out to the detailed guides underneath it, including this one. If you are starting from scratch rather than solving a specific problem, read that first and come back here.

FAQ

Q: What is Huffman coding?
A: A method of assigning short binary codes to frequent symbols and longer ones to rare symbols, built by combining the two least frequent symbols repeatedly into a tree. It is provably optimal for symbol-by-symbol coding and needs no separators between codes.

Q: Is it still used?
A: Yes, in JPEG, MP3, PNG, ZIP, MPEG and many other formats, usually as the final lossless stage after a transform and quantisation.