When the size of the table is large and it is arranged in some sequence –either ascending or descending on search field, then BINARY SEARCH would be the efficient method.
SEARCH ALL identifier-1 AT END imperative-statement-1
WHEN dataname-1 = identifier-2/literal-1/arithmetic expression-1
AND dataname-2 = identifier-3/literal-2/arithmetic expression-2
END-SEARCH.
Identifier-2 and identifier-3 are subscripted items and dataname-1 and dataname-2 are working storage items that are not subscripted.
Compare the item to be searched with the item at the center. If it matches fine, else repeat the process with the left or right half depending on where the item lies.
Sl # | Sequential SEARCH | Binary SEARCH |
1 | SEARCH | SEARCH ALL |
2 | Table should have INDEX | Table should have INDEX |
3 | Table need not be in SORTED order. | Table should be in sorted order of the searching argument. There should be ASCENDING/DESCENDING Clause. |
4 | Multiple WHEN conditions can be coded. | Only one WHEN condition can be coded. |
5. | Any logical comparison is possible. | Only = is possible. Only AND is possible in compound conditions. |
6 | Index should be set to 1 before using SEARCH | Index need not be set to 1 before SEARCH ALL. |
7 | Prefer when the table size is small | Prefer when the table size is significantly large. |
No comments:
Post a Comment