For a -ary code with codeword lengths , Kraft inequality isChoose 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.
Solved by gpt-5.6-sol high.
Codex Wiki