Hostname: page-component-7479d7b7d-t6hkb Total loading time: 0 Render date: 2024-07-12T12:43:47.547Z Has data issue: false hasContentIssue false

Functional Pearls Two greedy algorithms

Published online by Cambridge University Press:  07 November 2008

R.S. Bird
Affiliation:
Programming Research Group, Oxford University, 11 Keble Rd, Oxford OX1 3QD, UK
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.

At the recent TC2 working conference on constructing programs from specifications (Moeller, 1991), I presented the derivation of a functional program for solving a problem posed by Knuth (1990). Slightly simplified, the problem was to construct a shortest decimal fraction representing a given integer multiple of 1/216. Later in the conference – and in a different context – Robert Dewar described a second problem that he had recently set as an examination question. In brief, the problem was to replace sequences of blanks in a file by tab characters wherever possible. Although Knuth's and Dewar's problems appear to have little in common, I suspected that both had the same ‘deep structure’ and were instances of a single general result about greedy algorithms. The purpose of this note is to bring the genral result to light and to unify the treatment of the two problems. We begin by describing the problems more precisely.

Type
Articles
Copyright
Copyright © Cambridge University Press 1992

References

Bird, R. S. and Wadler, P. 1988. Introduction to Functional Programming. Prentice Hall.Google Scholar
Moeller, B. (Editor). 1991. Constructing Programs from Specifications. North-Holland.Google Scholar
Knuth, D. E. 1990. A simple program whose proof isn't. In Beauty is our Business, (Feijen, W., Gries, D., van Gasteren, N., editors). Springer-Verlag.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.