Distribution-Sensitive Construction of Minimum-Redundancy Prefix Codes

A new method for constructing minimum-redundancy prefix codes is described. This method does not build a Huffman tree; instead it uses a property of optimal codes to find the codeword length of each weight. The running time of the algorithm is shown to be O(nk), where n is the number of weights and k is the number of different codeword lengths. When the given sequence of weights is already sorted, it is shown that the codes can be constructed using O(log2k−1n) comparisons, which is sub-linear if the value of k is small.