Jump to content

Perfect hash function

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 212.179.248.144 (talk) at 15:51, 15 July 2003. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Perfect hash functions are hash functions which guarantee O(1) operations complexity when used in a hash table; In other words, a hash table that uses a perfect hash function guarantees that retrieving any value will take no more that some constant time, regardless of the table's size.
This is opposed to a general hash function, which may, in some conditions, require a number of look-ups that is proportional to the table's size - O(n) operations.

Coming up with a perfect hash function for a specific data set takes in the order of O(n) operations (i.e. a number of operations that is proportional to the data-set's size);
Using a perfect hash function is best at situations where there is a large dataset which is not updated frequently, and many look-ups into it. This is because updates may require re-calculation of the perfect hash.