arXiv:2611.04444cs.DSNov 2026

Manuscript Offprint

arXiv:2611.04444

Binary Huffman Coding with Unequal Letter Costs Is NP-Complete

L. Sunil Chandran, Rishikesh Gajjala

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Given positive frequencies for a set of source symbols, the binary prefix coding problem asks for an assignment of binary codewords, with no codeword being a prefix of another, that minimizes the frequency-weighted sum of codeword lengths. In 1952, Huffman solved this problem with a polynomial-time greedy algorithm. In the unequal-letter-cost version, the encoding letters 0 and 1 have different costs. The cost of a codeword is the sum of its letter costs, and the objective is to minimize the frequency-weighted sum of codeword costs. In 1961, Karp gave an integer-programming formulation for this generalization. Extensive subsequent work includes exact polynomial-time algorithms for fixed integer letter costs by Golin and Rote [IEEE Trans. Inf. Theory'98] and Bradford, Golin, Larmore, and Rytter [J. Algorithms'02]. For input-dependent letter costs, Golin, Mathieu, and Young gave a polynomial-time approximation scheme [SICOMP'12]. Despite this progress, the exact complexity when letter costs are part of the input had remained unresolved. We resolve this longstanding open problem by proving that deciding whether there exists a binary prefix-free code of cost at most a given threshold is NP-complete, even when the letter costs are consecutive positive integers (M,M+1)(M, M+1) supplied as part of the input. All frequencies, letter costs, and thresholds are encoded in binary. Consequently, finding an optimal code is NP-hard.

Our proof uses two polynomial-time reductions, starting from PLANAR INDEPENDENT SET. The intermediate problem prescribes the number of leaves at each depth of a full ordered binary tree and minimizes a signed linear score on their sorted coordinates. Here a coordinate counts the right edges on the path from the root. The graph reduction stores vertex choices in internal coordinates, copies them for edge tests, and uses the score to enforce the required transitions. A fixed-profile identity converts narrow coordinate restrictions into linear penalties. The second reduction assigns large dyadic terms to the symbol frequencies to force prescribed depths. These terms contribute a constant to the weighted number of ones, leaving smaller signed perturbations to reproduce the tree score.

Contents

1 Introduction 4 Our contribution ..... 4 Prior work ..... 6

2 The intermediate problem and proof overview 7 2.1 Trees, depths, and coordinate profiles ..... 7 2.2 The leaf-profile problem ..... 8 2.3 The intended solution correspondences ..... 10 2.4 Key ideas ..... 10

3 The first reduction: from the source problem to the leaf-profile problem 12 3.1 Construction: from graph to leaf profile ..... 12 3.1.1 A planar drawing and the sweep order ..... 12 3.1.2 Converting the graph into a program ..... 14 3.1.3 Instruction blocks and templates ..... 18 3.1.4 Coordinate placement and block assembly ..... 23 3.1.5 Generating the intermediate target instance from the intermediate code ..... 25 3.2 Execution: from an independent set to a feasible tree ..... 27 3.3 From a feasible tree of the leaf-profile problem back to an independent set ..... 28 3.3.1 Leaf compliance from the interval identity ..... 28 3.3.2 Instruction correctness: compatibility with an intended execution ..... 29 3.4 Guarantees of the first reduction ..... 30

4 From leaf scores to letter costs 31 4.1 Constructing the coding instance ..... 31 4.2 A three-symbol example ..... 32 4.3 Guarantees and proof ..... 32 4.4 Completing the NP-completeness proof ..... 35

Concluding remarks 36

AI Methodology 36

References 36

References (28)