A computer stores text by giving every character the same number of bits — eight for ASCII, for example. But that is wasteful. In English the letter e turns up constantly while z is rare, yet both get the same eight bits. Why pay full price for a letter that hardly ever appears?
The fix feels obvious once you hear it: give frequent symbols short codes and rare symbols long codes. That is exactly what Morse code did by hand a century ago — e is a single dot, q is a long dash-dash-dot-dash.
The catch is doing it optimally. Among the astronomically many ways to assign short and long codes, which one squeezes a given text into the fewest bits — and can you find it without a forbidding search? In 1952 a graduate student named David A. Huffman answered with a method so simple it fits in a paragraph, and so good it is provably the best any prefix code can do.
Comments
Loading comments...