Canonical Huffman codes for the six-symbol set — Huffman coding
coresame lengths, standard assignment
Answer
a=0 b=100 c=101 d=110 e=1110 f=1111
Why this example is worth doing
The code lengths are forced by the algorithm but the actual bit patterns are not — swapping the two children of any node gives a different, equally good code. Canonical Huffman fixes an assignment by sorting on length and then symbol, which means a decoder needs only the lengths rather than the whole tree. That is why real formats such as DEFLATE transmit lengths, and it is why this page always shows the canonical form alongside its own tree.
Try your own input in the Huffman coding. Build the tree from text or from frequencies, with the merge order and canonical codes.
How the answer is reached
Codebook
| symbol | code |
|---|---|
| a | 0 |
| b | 100 |
| c | 101 |
| d | 110 |
| e | 1110 |
| f | 1111 |
Merge order
| step | left | right | weight |
|---|---|---|---|
| 1 | 5 | 9 | 14 |
| 2 | 12 | 13 | 25 |
| 3 | 14 | 16 | 30 |
| 4 | 25 | 30 | 55 |
| 5 | 45 | 55 | 100 |