Past exam of the mathematics course of the University of Cambridge 2006 ii Paper 2 4G Solution Created 2026-09-24 Updated 2026-10-14
A decipherable code is one whose extension to finite strings by concatenation is injective: an encoded string has a unique sequence of source letters. In particular its codewords are distinct and nonempty. Put and . For strings of exactly source letters, let count the encoded strings of length . Unique decipherability gives , since distinct source strings yield distinct encoded strings. Expanding givesTaking th roots and letting proves the McMillan inequality
Add to the four specified binary words. None of the resulting seven words is a proper suffix of another: the longer words end in , and their shorter terminal strings never equal another of the specified longer words. Thus this is a suffix code. Reading from the right determines the last codeword uniquely; deleting it and repeating proves unique decipherability. Its length sum is , in agreement with the bound.
Past exam of the mathematics course of the University of Cambridge 2010 ii Paper 1 4H Solution Created 2026-09-24 Updated 2026-10-14
A binary uniquely decodable code assigns a finite binary word to each source symbol, so that no two distinct finite sequences of source symbols have the same concatenated encoding. This does not require the stronger prefix property. All codeword lengths are positive.
Put and let count sequences of source symbols whose encoded total length is . Expanding the product givesUnique decodability makes these encodings distinct, so , the number of binary strings of that length. There are at most possible lengths. ThereforeTaking th roots and letting proves the McMillan inequality:
Past exam of the mathematics course of the University of Cambridge 2015 ii Paper 3 3G Solution Created 2026-09-24 Updated 2026-10-06
Order the prescribed lengths as . Construct a prefix code on the binary tree. At depth , previously assigned codewords exclude of the vertices. The Kraft inequality impliesso an available vertex can be assigned to the next symbol. None of the assigned words is a prefix of another. Reading each word up to the next assigned vertex gives unique decoding, so this constructs the required uniquely decodable code.
For completeness the same length inequality is necessary even for a uniquely decodable code which is not a prefix code. Write and . For successive symbols, distinct symbol strings have distinct concatenated codewords. At total length there are at most such strings. ThereforeTaking th roots and letting gives . This is the McMillan inequality.
Set . The relative entropy inequality givesHere Shannon entropy uses base , with . The relative entropy is nonnegative, with equality precisely when the two probability distributions coincide; this follows from . Consequently equality holds exactly whenIn particular all alphabet symbols must have positive probability for equality with finite prescribed lengths.