Hostname: page-component-78c5997874-lj6df Total loading time: 0 Render date: 2024-11-05T13:01:47.619Z Has data issue: false hasContentIssue false

An optimal, purely functional implementation of the Garsia–Wachs algorithm

Published online by Cambridge University Press:  21 January 2020

RICHARD S. BIRD*
Affiliation:
Department of Computer Science, Oxford University, Wolfson Building, Parks Road, Oxford, OX1 3QD, UK (e-mail: [email protected])
Rights & Permissions [Opens in a new window]

Extract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

The Garsia–Wachs algorithm is an algorithm for building a binary leaf tree whose cost is as small as possible. The problem and the algorithm are described in more detail below, but the task is essentially the same as that of building a Huffman coding tree with the added constraint that the fringe of the tree has to be exactly the given list of inputs (in Huffman coding, the fringe of the tree can be any permutation of the input). As we will show below, the Garsia–Wachs algorithm can be implemented with a linearithmic running time—a running time of O (n log n) steps for an input of length n, the same time bound as for Huffman coding.

Type
Functional Pearl
Copyright
© Cambridge University Press 2020

References

Bird, R. & Gibbons, J. (2020) Algorithm Design with Haskell. Cambridge University Press. To appear.Google Scholar
Filliâtre, J.-C. (2008) A functional implementation of the Garsia Wachs algorithm. In ACM SIGPLAN Workshop on ML, Victoria, British Columbia, Canada.CrossRefGoogle Scholar
Garsia, A. M. & Wachs, M. L. (1977) A new algorithm for minimum cost binary trees. SIAM J. Comput. 6(4), 622642.CrossRefGoogle Scholar
Gilbert, E. N. & Moore, E. F. (1959) Variable length binary encodings. Bell Syst. Tech. J. 38, 933968.CrossRefGoogle Scholar
Hu, T. C. (1982) Combinatorial Algorithms. Reading, MA: Addison-Wesley.Google Scholar
Hu, T. C. & Tucker, A. C. (1971) Optimal computer-search trees and variable-length alphabetic codes. SIAM J. Appl. Math. 21, 514532.CrossRefGoogle Scholar
Huet, G. (1997) The Zipper. J. Funct. Program. 7(5), 549554.CrossRefGoogle Scholar
Karpinski, M., Larmore, L. L. & Rytter, W. (1997) Correctness of constructing optimal alphabetic tree revisited. Theor. Comput. Sci. 180(1–2), 309324.CrossRefGoogle Scholar
Kingston, J. H. (1988) A new proof of the Garsia-Wachs Algorithm. J. Algorithms 9, 129136.CrossRefGoogle Scholar
Knuth, D. E. (1971) Optimum binary search trees. Acta Inf. 1(1), 1425.CrossRefGoogle Scholar
Knuth, D. E. (1998) The Art of Computer Programming, Volume 3: Sorting and Searching, 2nd ed. Reading, MA: Addison-Wesley.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.