Probability monotonicity of optimal prefix-code lengths
= Probability monotonicity of optimal prefix-code lengths
If symbols of probabilities $p_i>p_j$ have codeword lengths $l_i$ and $l_j$ in an optimal prefix code, then $l_i\leq l_j$. Otherwise, exchanging their codewords preserves the prefix property and changes the expected length by
$$
(p_i-p_j)(l_j-l_i)<0,
$$
contradicting optimality.