Linear detection method

In open addressing algorithm, the linear detection method is a method of conflict resolution hash, hash when a keyword found no conflict, you save a keyword, if a conflict occurs, it will detect a conflict address address, following sequentially linear search, until it finds a free address in order to resolve the conflict,

{} Key set 7,8,30,11,18,9,14 e.g., a hash function: H (key) = (keyx3) MOD 7, provided filling factor (the number of elements / hash table length) of 0.7 , then the length of the hash table is 10.

Key (key) set of storage location are as follows:

7 8 30 11 18 9 14
0 3 6 5 5 6 0

We know from the table, where the 7 and 14, 30 and 9, 11 and 18 appeared in the location to the conflict. When storing key = 7, the length of the hash table 10 in fact there is no conflict, since 7 is the first table to the key exists, it will not have a conflict, so the hash table address 7 corresponding to 0.8, 30, 11 are stored in addresses 3, 6, 5, but when key = 18 to find the address 5 is stored, and the address has been stored for 5 key = 11, the time address conflicts occurred. The linear detection method, the algorithm will detect the address of the next address is 5, i.e. the address 6, the address 6 has been stored at a time when a key = 30, the program continues to detect an address, the address found 7 empty, when the key = 18 stored at an address 7. And so, finally resulting hash table is:

The last set of storage location
0 1 2 3 4 5 6 7 8 9
7 14   8   11 30 18 9  

Find Success rate: (1 + 1 + 1 + 1 + 3 + 3 + 2) / 7

Find unsuccessful rate

Find the number of unsuccessful calculation directly find keywords to the keyword from the empty can on the first address, the hash function address MOD7, so only the initial position may be 0-6. Under circumstances such as probability, find the 0-6 position number lookup failed to find:

   Address 0, the first key is the empty address from 2 to 3, so the search is unsuccessful number is three.  

   Address 1, a key to the first empty address from 2 to 2, so look for the number of unsuccessful 2.

        Address 2, a critical distance to the first empty address 2 to 1, so finding unsuccessful number is 1.

        Address 3, the first key from the empty address 4 is 2, so look for the number of unsuccessful 2.

        4 address, the first key is empty address from 4 to 1, so the search is unsuccessful number is 1.

        Address 5, a key to the first empty address 2 (note not address 9, is only possible because the initial between 0 to 6, and therefore loops back) the distance is 5, so look for the number of unsuccessful 5.

        Address 6, a key to the first empty address 2 (note not address 9, is only possible because the initial between 0 to 6, and therefore loops back) the distance is 4, so look for the number of unsuccessful 4.

Unsuccessful lookup rates: (3 + 2 + 1 + 1 + 2 + 4 + 5) / 7

 

Guess you like

Origin www.cnblogs.com/longerQiu/p/11703441.html