Huffman Coding & Information Theory

Build a Huffman code for any text — the optimal prefix-free code. See the code tree, per-symbol entropy, compression ratio, and how it approaches the Shannon entropy bound.

Shannon's source coding theorem (1948): the expected code length H(X) ≤ L < H(X)+1 for Huffman codes, where H(X)=-Σpᵢlog₂pᵢ. Huffman codes are optimal among prefix-free codes. The gap from H(X) measures redundancy — arithmetic coding can achieve exactly H(X).