We study a wide generalization of two classical problems, the Huffman Tree and Alphabetic Tree Problem. We assume that the cost caused by the ith leaf is fi(di), where di is its depth in the tree under consideration, and fi : N0 R+ 0 is an arbitrary function. All solution methods known for the classical cases fail to compute the optimum here. For the generalized Alphabetic Tree Problem, we give a dynamic programming algorithm solving it in time O(n4 ), using space O(n3 ). Furthermore, we show that the runtime can be reduced to O(n3 ) if the cost functions are nondecreasing and convex. The improved algorithm can also be used in the setting where the cost functions are nondecreasing and the objective function is the maximum leaf cost. We also prove that the Huffman Tree Problem in its full generality is inapproximable unless P=NP, no matter if the objective function is the sum of leaf costs or their maximum. For the latter problem, we show that the case where the cost functions are non...