For a minimum length code, length of symbols should be in the opposite order of the probability of the symbol occuring.
We want a instantaneous, uniquely decodable code for given set of input symbols , along with their probabilities .
Theorem
If are in descending order, then should be in ascending order
Proof
Suppose are in order, but at least one pair of are not.
Their contribution to the average length is
After interchanging the two codes
Difference is
One of these two is factors is negative, hence the difference is negative. So if we interchange, we get a smaller contribution to the average length . This means that in a minimum length code, the two running inequalities must be true.
Source: The Art of Doing Science and Engineering: Learning to learn