Given a list C = [c(1), c(2), ... , c(N)], c(k) = f(x(k)) greater than or equal to 0 and x(1) < x(2) < ... x(N), the histogram-equalization problem consists of decomposing the list C into M less than or equal to N pieces or intervals, where each interval is a group of one or more consecutive c(k)'s, such that the sum of c(k)'s for the various intervals are as uniform as possible. We give an O(MN2) algorithm for computing an optimal decomposition by converting it to a shortest path problem in a suitable digraph and using a modified form of Floyd's algorithm for computing a shortest path. A number of other decomposition problems, which have applications in curve fitting by step-functions and image compression, can be solved by the same method. (C) 1997 Pattern Recognition Society. Published by Elsevier Science Ltd.