Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary Search vs SEARCH ALL

Status
Not open for further replies.

cobolenterprise

Programmer
Oct 22, 2005
2
0
0
US
Which is more efficient? Manual Binary search (using various nested IFs) or SEARCH ALL function? I need to search an entry in a sorted table of 2000 elements, and this check will happen for million records for a job. There are 1000s of similar jobs that will run every day.


Help me out,
Cobol Learner
 
Nested IFs, I mean using coding Binary search algorithm (using High, Low, Mid checks) ...........
 
The search all is a binary search. That is the fastest way if you have to find random info. If you have sorted info, you can perhaps use a balance-line approach which will be faster if the data is sorted. So it depends on your situation. The binary search will never be bad.
 
It depends on what kind of approach the SEARCH ALL is coded. As people in these fora have been fond of telling me, SEARCH ALL doesn't have to equal "binary search", but the data have to be SORTED somehow for the SEARCH ALL to be relevant. So for the OP, the proper answer is "your mileage may vary, but it's going to be much better than SEARCH as long as your data are sorted.
 
Another approach that can pay dividends depending on how well you know your data (e.g. 25 % of the searches are for a specific key) is to an if stmt or whatever before the search.

IF ARG = KEYX MOVE TBL-DATA(KEYX) etc...
ELSE
SEARCH TBL-X...

Another efficiency trick is to move the tbl entry to a ws field and then use the ws field from that point on.

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top