Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

umm well a string of three characters ( T,C,G,A) , from among these, will be given to the hash function which will generate an index. Can i simply do something like this, if the input is TTT index is 0 , if TCT , index is 1 and so on

OpenStudy (anonymous):

int findIndex ( char *arr ) { int sum , x , i , b , z ; i = 0; int y = strlen(arr); x = arr[0]; x = (x*x)%10; b = arr[1]; z = arr[2]; z = (z*z); sum = x-b+z; return (sum%64); }

OpenStudy (anonymous):

I have this hash function , it gives 20 collissions . Is this a correct hash function ? Also how can i make it a perfect hash function

myininaya (myininaya):

omg i don't know this much about hash functions i only really know about the math behind it i;m sorry :(

OpenStudy (anonymous):

:( its ok :)

OpenStudy (shadowfiend):

How much capacity will your hashtable have? That will decide whether you will find it possible to have a perfect hash function or not.

OpenStudy (anonymous):

hash table can be of 128 size at maximum

OpenStudy (anonymous):

I imagine there are different implementations of hash. You will have some collisions depending on the number of different inputs you have. Although you can build your own hash functions as you describe above, the built in implementations are likely to be more efficient and set up so that the compiler can optimize them better than probably anything you would write. If your task is not specifically to build a hash implementation, I would go with the built in class(es).

OpenStudy (shadowfiend):

Ok, if the table can be 128 size maximum, 4 letters 3 at a time gives you a maximum of 24 permutations, so you know you can find a perfect hash function. You need to basically figure out a way that each possible string can be assigned a number from 0 to 24, and then any hashtable size above 23 will have a perfect hash function for it.

OpenStudy (anonymous):

Thanks alot everyone! :)

OpenStudy (shadowfiend):

You're welcome :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!