Huffman coding Always merge the two least-probable nodes. The result is a prefix-free code whose average length is within 1 bit of entropy. Green = near-optimal length.
Huffman Coding - Interactive Visualization
Huffman coding builds an optimal prefix-free code: frequent symbols get short codewords, rare symbols get long ones. The algorithm greedily merges the two lowest-probability symbols at each step. The expected code length approaches the entropy H(X) - Shannon's bound on lossless compression. This visualization steps through Huffman tree construction and shows the final codewords.
Adjust symbol probabilities and step through Huffman tree construction
See each merge step: lowest-probability symbols combine first
Read codewords from root-to-leaf paths (0=left, 1=right)
Compare average code length to entropy H(X)
Foundation for GZIP, PNG, and general-purpose data compression
Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.