Fast dictator in C without linear search
4 answers
Use a Hash Table . The hash table will have a persistent lookup. Here are some excerpts from C and a C (and Portuguese) implementation :) .
+6
source to share
You need to implement a Hash Table that stores objects using a hash code. The search time is constant.
A Binary tree can traverse and search for an element in log (n) time.
+2
source to share
If the strings are long, you won't be able to consider the "Hash Table" constant! execution time depends on the length of the string! for long lines this will cause problems. also, you have the problem of collisions with too small table or too bad hash function.
if you want to use hashing look at rabin carp. if you want to be dependent on the SOLELY algorithm for the word size you are looking for, please have a look at aho-corasick.
+1
source to share