Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hash Function Determination

How can we find the most efficient hash function(least possible chances of collision) for the set of strings.

Suppose we are given with some strings.. And the length of the strings is also not defined. Ajay Vijay Rakhi ....

we know the count of no. of strings available, so we can design a hash table of size(count available). what could be the perfect hash function that we could design for such problem??

Multiplying each character ascii value by 31(prime no.) in increment fashion leads to the a hash value greater than the value of MAX_INT, and then modulus would not work properly... So please give some efficient hash function build up solution....

I have few set of strings,, lets say count = 10.... I need to implement a hash function such that all those 10 strings fit in uniquely in the hash table.... Any perfect hash function O(1) available, for this kind of problem?? hash table size will be 10, for this case...

Only C Programming...

Please explain the logic at website.... http://burtleburtle.net/bob/c/perfect.c This looks very complicated but perfect to me..!! what is the algorithm used here... Reading the code straight away, is very difficult!!

Thanks....

like image 782
AGeek Avatar asked Mar 16 '11 17:03

AGeek


People also ask

What does hash function determine?

Hash functions can be used to determine if two objects are equal (possibly with a fixed average number of mistakes). Other common uses of hash functions are checksums over a large amount of data (e.g., the cyclic redundancy check [CRC]) and finding an entry in a database by a key value.

How do I choose a hash function?

Choosing a good hashing function, h(k), is essential for hash-table based searching. h should distribute the elements of our collection as uniformly as possible to the "slots" of the hash table. The key criterion is that there should be a minimum number of collisions. will provide uniform hashing.

What are the 3 main properties of hash function?

In particular, cryptographic hash functions exhibit these three properties: They are “collision-free.” This means that no two input hashes should map to the same output hash. They can be hidden. It should be difficult to guess the input value for a hash function from its output.

How the hash value is calculated?

Hashing involves applying a hashing algorithm to a data item, known as the hashing key, to create a hash value. Hashing algorithms take a large range of values (such as all possible strings or all possible files) and map them onto a smaller set of values (such as a 128 bit number). Hashing has two main applications.


2 Answers

Check some of these out, they apparantly have good distributions

http://www.partow.net/programming/hashfunctions/#HashingMethodologies

like image 51
deek0146 Avatar answered Sep 17 '22 17:09

deek0146


You might want to look into perfect hashing.

like image 27
Philipp T. Avatar answered Sep 17 '22 17:09

Philipp T.