Searching a table
COBOL provides two search techniques for tables: serial and binary.
About this task
To do serial searches, use SEARCH
and indexing.
For variable-length tables, you can
use PERFORM
with subscripting or indexing.
To do binary searches, use SEARCH ALL
and indexing.
A binary search can be considerably more efficient than a serial search. For a serial search, the number of comparisons is of the order of n, the number of entries in the table. For a binary search, the number of comparisons is of the order of only the logarithm (base 2) of n. A binary search, however, requires that the table items already be sorted.