In the partial alphabetic tree problem we are given a multiset of non-negative weights W = {w(1),..., w(n)}, partitioned into m <=, n blocks B-1,.... B-m. We want to find a binary tree T where the elements of W reside 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 Sigma(n)(i=1) w(i)d(w(i)), where d(w(i)) is the depth of uti in T. The partial alphabetic tree problem generalizes the problem of finding a Huffman tree over W (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 problem arises when we need 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 alpha) log(W-sum/W-min)n(2)) time where W-sum = Sigma(i=1)(n) w(i), W-min = min(i) w(i), and alpha = 1/log phi approximate to 1.44 (phi = (root 5 + 1)/2 approximate to 1.618 is the golden ratio). In 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 [alpha log(W-sum/W-min) + 0.56] on the depth of the optimal tree. Our algorithm relies on a solution to what we call the layered Huffman 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(k)). We look for a forest F with k trees, T-1..., T-k, where the weights in W correspond to the leaves of F, that minimizes Sigma(n)(i=1) w(i)d(F)(w(i)) where d(F)(w(i)) is the depth of w(i) in its tree plus d(j) if w(i) is an element of T-j. Our algorithm for this problem runs in O(kn(2)) time. (C) 2005 Elsevier Inc. All rights reserved.