Solution

ID: past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2022/ii/paper-1/3k/a/solution

For a -ary code with codeword lengths , Kraft inequality is
Choose an infinite random -ary string with independent uniform symbols. The event that it begins with codeword has probability . For a prefix-free code, these events are disjoint, so their probabilities sum to at most one. This proves necessity.

New to topics? Read the docs here!