The problem of finding optimal prefix-free codes for unequal letter costs consists of computing a minimum cost prefix-free code in which the encoding alphabet consists of unequal cost (length) letters, of lengths α and β, where α ≤ β. We restrict ourselves limited to binary trees.
The code is represented by a lopsided tree, in the similar way as a Huffman tree represents the solution of the Huffman coding problem. Despite the similarity, the case of unequal letter costs is much difficult than the classical Huffman problem; no polynomial time algorithm is known or available for general letter costs, despite a rich literature on the problem.
However, there are known polynomial time algorithms available α and β are integer constants.
The problem of computing the least cost tree in this case was first studied by Karp in 1961 who solved the problem by reduction to integer linear programming, producing an algorithm exponential in both n and β. Since that time there has been much work on various aspects of the problem such as; bounding the cost of the optimal tree; the limitation to the special case when all of the weights are equal.
Despite all of these efforts it is still, surprisingly, unknown whether the basic problem is polynomial-time solvable or in NP -complete.
Golin and Rote describe an O(nβ+2)-time dynamic programming algorithm that builds the tree in a top-down fashion.
This has been improved implementing a different approach (monotone-matrix concepts, e.g., the Monge property and the SMAWK algorithm.
THEOREM 1: Optimal lopsided trees can be constructed in O(nβ ) time.
This is the most efficient known algorithm for the case of small value of β; in practice the letter costs are typically small (e.g., Morse codes).
Recently a scheme of an efficient approximating algorithm has been provided.
There is a polynomial time approximation scheme for optimal lopsided trees.