Next: A possible algorithm: linear
Up: Introduction
Previous: An example: searching
  Contents
We are now ready to formulate the specification of our search problem:
Given an array
and integer
, find an integer
such that
- if there is no
such that
is
, then
is
,
- otherwise,
is
.
The first clause says that if
doesn't occur in the array then
should be
, and the second says that if it does then
should be
a position where it occurs. If there is more than one position where
occurs, then this specification allows you to return any of them
-- this would be the case e.g. if
were
and
were
. Thus, the specification is ambiguous. Hence different
algorithms with different behaviours can satisfy the same
specification -- for example, one algorithm may return the smallest
position at which
occurs and an another the largest. There is
nothing wrong with ambiguous specifications. In fact, they do occur in
practice often.
Next: A possible algorithm: linear
Up: Introduction
Previous: An example: searching
  Contents
Martin Escardo
2005-01-11