In the partial alphabetic tree problem we are given a multiset of nonnegative weights
W =
w
1, . . . ,
w
n
, partitioned into
k ≤
n blocks
B
1, . . . ,
B
k. We want to find a binary tree
T where the elements of
W resides in its leaves such that if we traverse the leaves from left to right then all leaves of
B
i precede all leaves of
B
j for every
i <
j. Furthermore among all such trees,
T has to minimize ∑
n
i
=1
wid(
wi), where
d(
wi) is the depth of
wiin
T. The partial alphabetic tree problem generalizes the problem of finding a Huffman tree over
T (there is only one block) and the problem of finding a minimum cost alphabetic tree over
W ( each block consists of a single item). This fundamental problem arises when we want to find an optimal search tree over
a set of items which may have equal keys and when we want to find an optimal binary code for a set of items with known frequencies,
such that we have a lexicographic restriction for some of the codewords. Our main result is a pseudo-polynomial time algorithm
that finds the optimal tree. Our algorithm runs in
O(
W
sum/
W
min)
2α log(
W
sum/
W
min)
n
2) time where
W
sum= ∑
n
i
=1
wi,
W
min= min
i
wi, and α = 1/log ∅ 1.44
1. I n particular the running time is polynomial in case the weights are bounded by a polynomial of
n. To bound the running time of our algorithm we prove an upper bound of ⌊α log(
W
sum/
W
min) + 1⌋ on the depth of the optimal tree.
Our algorithm relies on a solution to what we call the layered Hu.- man forest problem which is of independent interest. In
the layered Huffman forest problem we are given an unordered multiset of weights W = w
1, . . . , w
n, and a multiset of integers D = d
1, . . . , d
m. We look for a forest F with m trees, T
1, . . . , T
m, where the weights in W correspond to the leaves of F, that minimizes ∑
n
i
=1 widF(wi) where dF(wi) is the depth of wiin its tree plus dj if wi ∈ Tj. Our algorithm for this problem runs in O(kn
2) time.
∅ = √5+12 1.618 is the golden ratio