Click here to Skip to main content
15,919,479 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionEfficient Search/Comparison Algorithm Pin
SanchitK20-Nov-08 3:29
SanchitK20-Nov-08 3:29 
AnswerRe: Efficient Search/Comparison Algorithm Pin
Member 419459320-Nov-08 6:17
Member 419459320-Nov-08 6:17 
AnswerRe: Efficient Search/Comparison Algorithm Pin
Alan Balkany20-Nov-08 10:20
Alan Balkany20-Nov-08 10:20 
AnswerRe: Efficient Search/Comparison Algorithm Pin
cmk20-Nov-08 12:59
cmk20-Nov-08 12:59 
GeneralRe: Efficient Search/Comparison Algorithm Pin
Member 419459320-Nov-08 14:18
Member 419459320-Nov-08 14:18 
GeneralRe: Efficient Search/Comparison Algorithm Pin
cmk20-Nov-08 16:21
cmk20-Nov-08 16:21 
GeneralRe: Efficient Search/Comparison Algorithm Pin
Alan Balkany21-Nov-08 3:35
Alan Balkany21-Nov-08 3:35 
GeneralRe: Efficient Search/Comparison Algorithm Pin
supercat921-Nov-08 9:44
supercat921-Nov-08 9:44 
If it's necessary to check billions of records per day, that sounds like enough computer work--regardless of algorithm--that profiling will be necessary to achieve optimal performance. Radix trees can be good if the records to be searched for differ from other records in the characters that are examined first. They can be bad if records often differ only in the characters that are examined much later.

With hash functions, there is often going to be some trade-offs involving the time required to perform a hash, the hash table size, and the frequency of hash collisions and false matches. Increasing the complexity of a hash function such that the time required increases by more than half the cost of a direct record comparison won't make much sense if doing so unless it saves an average of one direct record comparison for every two records. Having a hash table so large that every access entails a cache miss may slow things down more than would the occasional hash collision or false match.

One approach that may be helpful would be to compute a somewhat long hash of a record, hash that to produce an index into a hash table, and have the table itself store the 'long' hash in addition to the actual record. One could thus at very little expense test the long hash of the record to be checked against the long hash in the table. This would eliminate a large fraction of the direct record comparisons that would otherwise be needed.

BTW, how fast are modern machines at 32x32 integer multiplication? If the strings are zero-padded as well as zero-terminated and multiplies are cheap, it might be good to do something like:
unsigned long *ptr;
unsigned long hash,temp;

/* Point ptr at the start of the data, preferably word aligned */
do
{
  temp = *ptr++;
  hash += hash >> 23;
  hash ^= temp;
  hash *= some_big_prime_number;
} while(temp);

That would gobble up 32 bits of string data per loop iteration; I would expect the multiply, even if it takes multiple cycles, could be done concurrently with the next word fetch. Not the world's most sophisticated hash function by any stretch, but the execution time should be pretty minimal. If you want to use the hash function to yield a table index, use the upper bits. Taking the modulus of a prime number (distinct from the one used for the multiply) may be better, but modulus operations are more expensive than shifts.
GeneralRe: Efficient Search/Comparison Algorithm Pin
Alan Balkany21-Nov-08 11:35
Alan Balkany21-Nov-08 11:35 
Question[Message Deleted] Pin
De@r17-Nov-08 3:45
De@r17-Nov-08 3:45 
AnswerRe: convert bubble sort to quick sort Pin
73Zeppelin17-Nov-08 5:48
73Zeppelin17-Nov-08 5:48 
QuestionWumpus problem Pin
hockymot2008_200915-Nov-08 3:32
hockymot2008_200915-Nov-08 3:32 
AnswerRe: Wumpus problem Pin
Reynolds Glisner15-Nov-08 13:23
Reynolds Glisner15-Nov-08 13:23 
GeneralRe: Wumpus problem Pin
hockymot2008_200916-Nov-08 4:25
hockymot2008_200916-Nov-08 4:25 
GeneralRe: Wumpus problem Pin
Member 419459316-Nov-08 4:59
Member 419459316-Nov-08 4:59 
GeneralRe: Wumpus problem Pin
Mark Churchill16-Nov-08 13:07
Mark Churchill16-Nov-08 13:07 
AnswerRe: Wumpus problem Pin
73Zeppelin16-Nov-08 6:04
73Zeppelin16-Nov-08 6:04 
Questionhow to convert plural word to singular? Pin
hawkgao012913-Nov-08 23:49
hawkgao012913-Nov-08 23:49 
AnswerRe: how to convert plural word to singular? Pin
73Zeppelin14-Nov-08 0:39
73Zeppelin14-Nov-08 0:39 
GeneralRe: how to convert plural word to singular? Pin
User 171649214-Nov-08 1:13
professionalUser 171649214-Nov-08 1:13 
GeneralRe: how to convert plural word to singular? Pin
73Zeppelin14-Nov-08 2:18
73Zeppelin14-Nov-08 2:18 
AnswerRe: how to convert plural word to singular? Pin
User 171649214-Nov-08 1:39
professionalUser 171649214-Nov-08 1:39 
QuestionTable comparison material Pin
aggressor_us12-Nov-08 13:29
aggressor_us12-Nov-08 13:29 
AnswerRe: Table comparison material Pin
Member 419459315-Nov-08 12:22
Member 419459315-Nov-08 12:22 
GeneralRe: Table comparison material Pin
aggressorus17-Nov-08 6:09
aggressorus17-Nov-08 6:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.