Huffman Merges on Three Frequencies

A binary Huffman construction repeatedly combines the two least available weights, making their subtrees siblings.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace three weights
  2. Compute the resulting cost
  3. Merge the two smallest weights and compute weighted path cost
  4. Handle ties and code transmission explicitly

Trace three weights

For weights five, two, and one, first combine two and one to get three. Combine that three with five at the root. The weight-five symbol has length one and the others length two. See weighted expected lengths.

Compute the resulting cost

For these eight observations, code length contributes \(5+2\cdot2+1\cdot2=11\) bits without a code table or framing. Huffman coding explains why the merge rule is optimal for its objective.[1][2]

Merge the two smallest weights and compute weighted path cost

For symbols A, B and C with weights six, three and one, merge B and C into weight four. Merge that node with A to form the root. A has depth one, B and C depth two, for weighted cost fourteen over ten symbols. See expected variable-length cost.

Merge 1+3=4
Merge 4+6=10
Weighted cost: 6×1 + 3×2 + 1×2 = 14 bits
Mean 1.4 bits per symbol under these counts

Handle ties and code transmission explicitly

Different tie choices can produce different exact bit assignments without changing the optimal weighted cost. A decoder must know the chosen tree or a representation of its code lengths.

References

  1. David A. Huffman, A Method for the Construction of Minimum-Redundancy Codes ↩
  2. David J. C. MacKay, Information Theory, Inference, and Learning Algorithms ↩