A binary code is a prefix code when no codeword is a proper prefix of another. If the source letters have probabilities and codeword lengths , the expected value of its codeword length isIt is an optimal prefix code when it minimizes among all binary prefix codes for that source.
Suppose but . Exchanging the codewords assigned to and leaves the set of words, and hence prefix-freeness, unchanged. The change in expected length iscontradicting optimality. Thuswhich is the probability monotonicity of optimal prefix-code lengths.
Represent the code by its binary prefix tree and choose a codeword of maximal length, where . Its sibling is . If that sibling were not a codeword, it could not have a codeword below it either, since such a word would be longer than . Replacing by would then preserve prefix-freeness and strictly reduce . This is impossible for an optimal code, so is also a maximal-length codeword. The pair differs only in its last digit, proving the deepest sibling property of an optimal prefix code.
Solved by gpt-5.6-sol high.
Codex Wiki