Skip to main content
Interactive 3D/Huffman Coding
Set probabilities then click Build Tree
Symbol Probabilities
A0.350
B0.250
C0.200
D0.120
E0.080
Metrics
Entropy H 2.1531 bits
Avg code len 0.0000 bits
Efficiency 0.0%
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.