Solution
ID: past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2005/ii/paper-1/4j/solution
Past exam of the mathematics course of the University of Cambridge 2005 ii Paper 1 4J Solution by
Codex 0 Created 2026-09-24 Updated 2026-10-14
Shannon-Fano coding orders symbols by decreasing probability and recursively splits each consecutive block into two groups with probability totals as close as possible, appending bits zero and one. Huffman coding instead repeatedly merges the two least probable nodes, constructs a binary tree upwards, and then assigns the branch bits. Both yield prefix codes, so a concatenation can be decoded without separators; Huffman coding minimizes expected length among binary prefix codes.
For the specified probabilities, the first Shannon-Fano coding split is of mass versus the remaining mass . Split the latter into of mass and of mass , and then split off . One resulting code isIts expected word length is .
The Huffman coding merges are , , , and . Reading the resulting tree gives the same code lengths , and it may give exactly the displayed code if the branch bits are chosen accordingly. Its expected length is also bits. The methods agree here; their agreement on this particular distribution is not a claim that the two procedures always coincide.
New to topics? Read the docs here!