Published in Journal of Algorithms, Vol. 12, 1991, pp. 23-37.