The fundamental flaw of the hash: for any hash function, there is a bad health set, so that all the health will be hashed into the same slot, then how to solve this situation? How do I prevent a key set from ever having a poor performance? How do you prevent competitors from using this key set to reduce your performance? A word to solve the problem--random!

The whole-domain hash method is to randomly select a hash function h (not each operation will choose a hash function, but a hash table to build a random selection, after the selection of this hash table all operations are based on this hash function, this method can prevent the competitor design a key set of ulterior motives, It is also possible to avoid some key sets that will always lead to poor performance, and if so, rebuild a table! ）

Defined:

Set u as the whole domain of the key, H is the finite set of hashes, h each hash function h maps the set U to the M position of the hash table, if the hash table satisfies: two values in U x, y x≠y {h∈h:h (x) =h (y)}=| H|/m, then H is the whole domain.| H| means the number of hash functions in the whole domain, then take a function h from the inside, the probability that the function will hash x and Y to the same position is 1/m, that is, these functions are uniform functions.

Hash Function Group Constructionone of the following methods:

Take m as a prime number, take the random number A is r+1 bit m binary, expressed as <A0,A1,..., ar> (where 0 <= Ai <= m-1 is randomly selected), then the hash function H[a] (K) is defined as:

H[a] (K) = sum {Ai * Ki | i =0, 1, ..., m-1} mod m

Prove:

Proof of theorem

Full Hash

the basic flaw of hashing, even if the whole domain hash is constructed, is not necessarily able to solve the problem of bad keyset input, can you find a perfect solution? can you guarantee that the complexity of finding in any case is in θ (1)? And the hash table is not too big to meet N=o (m)now to do the reasoning, if we ask for any number x in the hash table, the expected number of collisions, less than 1in the case of uniform hashing, the likelihood of collisions is 1/m for each number, socn2*1/m=n (n-1)/2m <1 so M>n (n-1)/2 that is, M is the magnitude of the square of N, so an ordinary hash table is not possible to accomplish this task unless the hash table is constructed very large. The solution is to construct a double-layered hash structure, where the bottom of the hash table is used to hold the second level of the entry pointer and the hash function used, and the second layer is the data element that proves slightly

Full domain hash and full hash--Introduction to MIT Algorithm Open class

This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to info-contact@alibabacloud.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.

Try 40+ Products For Free !

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.