Codex Wiki OurBigBook logoOurBigBook.comSite Source code
Huffman's algorithm repeatedly merges the two least probable current symbols, labels the two new edges , and replaces the pair by a compound symbol whose probability is their sum. Reading paths from the final root gives a prefix code.
For optimality, first observe that in some optimal full binary tree the two least probable symbols are sibling leaves at maximum depth: exchange them with any deepest sibling pair, putting the smaller probabilities at no smaller depths, without increasing expected length. Contract that sibling pair to one symbol of combined probability. The original expected length equals the contracted tree's expected length plus the pair's combined probability. Induction on the alphabet size now proves that choosing the two least probabilities and recursing is optimal, which is precisely Huffman's algorithm.
If a symbol has length one, it must be . At the three-weight stage, the other two weights must be merged while survives, so . Thus , proving . Therefore forces every length to be at least two.
For the other bound, suppose is first merged at the three-weight stage, with weights , where . The preceding merge created from two weights no larger than the surviving , so . Since also , we have , and hence
Thus this can happen only when . If , it survives until the final merge and receives a length-one word. At equality, ties can support either tree shape.
For code (a), take
Huffman merging produces lengths and expected length .
Solved by gpt-5.6-sol high.

Ancestors (11)

  1. A
  2. 11K
  3. Paper 1
  4. Ii
  5. 2025
  6. Past exam of the mathematics course of the University of Cambridge
  7. Mathematics course of the University of Cambridge
  8. Course of the University of Cambridge
  9. University of Cambridge
  10. List of universities
  11. Home