2 Specification

3 Description

nag_search_double (m01nac) is based on Professor Niklaus Wirth's implementation of the Binary Search algorithm (see Wirth (2004)), but with two modifications. First, if the sought-after item is less than the value of the first element of the array to be searched, -1 is returned. Second, if a value equal to the sought-after item is not found, the index of the immediate lower value is returned.

4 References

Wirth N (2004) Algorithms and Data Structures 35–36 Prentice Hall

5 Arguments

1:
validate – Nag_BooleanInput

On entry: if validate is set to Nag_TRUE argument checking will be performed. If validate is set to Nag_FALSE nag_search_double (m01nac) will be called without argument checking (which includes checking that array rv is sorted in ascending order) and the function will return with fail.code=NE_NOERROR. See Section 8 for further details.

7 Accuracy

Not applicable.

8 Further Comments

The argument validate should be used with caution. Set it to Nag_FALSE only if you are confident that the other arguments are correct, in particular that array rv is in fact arranged in ascending order. If you wish to search the same array rv many times, you are recommended to set validate to Nag_TRUE on first call of nag_search_double (m01nac) and to Nag_FALSE on subsequent calls, in order to minimize the amount of time spent checking rv, which may be significant if rv is large.

The time taken by nag_search_double (m01nac) is Olog⁡n, where n=m2-m1+1, when validate=Nag_FALSE.

9 Example

This example reads a list of double precision numbers and sought-after items and performs the search for these items.