×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Binary Search vs SEARCH ALL

Binary Search vs SEARCH ALL

Binary Search vs SEARCH ALL

(OP)
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

RE: Binary Search vs SEARCH ALL

(OP)
Nested IFs, I mean using coding Binary search algorithm (using High, Low, Mid checks) ...........

RE: Binary Search vs SEARCH ALL

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.

RE: Binary Search vs SEARCH ALL

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."

RE: Binary Search vs SEARCH ALL

You see, Glenn, you are teachable!    Good post!

Tom Morrison
www.liant.com

RE: Binary Search vs SEARCH ALL

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close