29. Why Are Prefix Codes Unambiguous? Since both c and c' can occur at the beginning of the text, we have x i = y i , for 0 ≤ i ≤ k ; that is, x 0 x 1 … x k is a prefix of y 0 y 2 … y l , a contradiction. It suffices to show that the first character can be decoded unambiguously. We then remove this character and are left with the problem of decoding the first character of the remaining text, and so on until the whole text has been decoded. c Assume that there are two characters c and c' that could potentially be the first characters in the text. Assume that the encodings are x 0 x 1 … x k and y 0 y 2 … y l . Assume further that k ≤ l . c c'
48. Lemma: If T' is optimal for C', then T is optimal for C. Assume the contrary. Then there exists a better tree T'' for C . Also, there exists a tree T''' at least as good as T'' for C where x and y are sibling leaves of maximal depth. The removal of x and y from T''' turns their parent into a leaf; we can associate this leaf with z . The cost of the resulting tree is B ( T''' ) – f ( x ) – f ( y ) < B ( T ) – f ( x ) – f ( y ) = B ( T' ). This contradicts the optimality of B ( T' ). Hence, T must be optimal for C .