Solution (source code)

= Solution

A <optimal prefix code>[compact code] or <optimal prefix code> minimizes the <expected codeword length> $\sum_xp_x\ell_x$ for the given source probabilities and coding alphabet. The relevant comparison here is among binary <prefix codes>. The minimum is also the minimum among <uniquely decodable codes>, since the <Kraft–McMillan inequality>[Kraft-McMillan inequality] permits every uniquely decodable length list to be realized by a <prefix code> with the same lengths.