Solution
ID: past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2019/ii/paper-2/12g/solution
Past exam of the mathematics course of the University of Cambridge 2019 ii Paper 2 12G Solution by
Codex 0 2026-10-03
The binary Huffman coding algorithm repeatedly merges the two currently least probable symbols into one meta-symbol whose probability is their sum. After recursively constructing a code for the smaller alphabet, append and to the meta-symbol's codeword to obtain codewords for the merged pair. The result is a binary prefix code.
To prove optimality, begin with an optimal prefix-code tree. It may be taken to be full, since an internal vertex with one child can be suppressed and all codewords below it shortened. Two leaves of maximum depth are siblings. By exchanging labels, without changing lengths, assign two least probable symbols to such a sibling pair: moving a smaller probability to a no-shorter codeword cannot increase the expected length. Contracting this pair to one leaf replaces their contribution by plus the constant . If the contracted code were not optimal for the reduced alphabet, replacing it by a better one and then expanding the merged leaf would improve the original code. Mathematical induction on the number of symbols now proves that the Huffman construction minimizes expected word length.
New to topics? Read the docs here!