Hostname: page-component-7479d7b7d-rvbq7 Total loading time: 0 Render date: 2024-07-12T21:19:11.804Z Has data issue: false hasContentIssue false

Functional Pearls: The Minout problem

Published online by Cambridge University Press:  07 November 2008

Richard S. Bird
Affiliation:
Programming Research Group, Oxford University
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 problem of computing the smallest natural number not contained in a given set of natural numbers has a number of practical applications. Typically, the given set represents the indices of a class of objects ‘in use’ and it is required to find a ‘free’ object with smallest index. Our purpose in this article is to derive a linear-time functional program for the problem. There is an easy solution if arrays capable of being accessed and updated in constant time are available, but we aim for an algorithm that employs only standard lists. Noteworthy is the fact that, although an algorithm using lists is the result, the derivation is carried out almost entirely in the world of sets.

Type
Article
Copyright
Copyright © Cambridge University Press 1991
Submit a response

Discussions

No Discussions have been published for this article.