CompuServe Messages

Help

    09-Aug-95 20:25:06
Sb: #47793-Help
Fm: Jim Butterfield 73624,14
To: john 70474,2354
"alphabetically sorted" may be something of a red herring.. but.. The traditional way to find an item in an ordered list is by a binary split search. In other words, you go to the middle of the list, and depending on whether your search value is higher or lower, move up or down 1/4 of the length of the list .. then 1/8, and so on. If your material is purely alphabetic, that is, you can depend on the first character being A through Z, you can save time over the above method by building a list: where A starts, where B starts, etc. You don't have to search THIS index list; just go straight to the letter you want to find a starting point for your search. A variation on the above is the "linked list"; all the As are linked together, then all the Bs, and so on. Nice thing about links is that you can set them up to search on more than one key value. You'll undoubtedly get a number of suggestions about putting your data into a "tree" structure, where each above/below test points you to the next set of tests to do. There are many variations on this one. If your objective is to find "hits" in the table – you don't care about values that will not turn out to find a match – you can go to a "hashing" technique. This is a little wasteful of memory, but it's real fast: by crunching together the alphabetic characters in mathematical fashion, you can generate an index number that will take you straight to the match, if it exists. Searching (and its cousin, sorting) is a major area of computer science study. Most of us cobble together something that works nicely for the application we have on hand. –Jim