hash conflict resolution

 

1. The open address method has a formula: m is the length of the hash table, and di is the incremental sequence when a conflict occurs

 

fi(key) = (f(key)+di) MOD m;   

Find the empty fi(key) position and put it in this position. When it reaches the end of the table m-1, it starts to probe from 0.

 

a. Linear detection method (di=0,1,2,3,...,m-1)  

b. Secondary detection method (linear compensation detection method) di=i^2,di=- (i^2); i=0,1,2,3,(m-1)/2

c. Random detection di is a series of pseudo-random numbers calculated using a deterministic algorithm that seems to be a random number sequence, so the pseudo-random numbers are not actually random. For example, the time on the computer is used as the starting value for calculating the pseudo-random numbers.

 

2. Rehashing

When there is a collision, use the second, third, hash function to calculate the address until there is no collision. Disadvantage: increased computation time.

For example, the first letter of the string is installed for hashing. If there is a conflict, the second letter can be hashed, and then the third one, until there is no conflict.

 

3. Chain address method

Store all records whose keywords are synonyms in the same linear linked list. as follows:



 

 

4. Create a common overflow area

Assuming that the value range of the hash function is [0, m-1], set the vector HashTable[0..m-1] as the basic table, and set up the storage space vector OverTable[0..v] to store the conflicting data. Record.

Through the above methods, the problem of hash algorithm conflict can be basically solved.

Note: The reason why hash is briefly introduced is to better learn the lzw algorithm, and to learn the lzw algorithm is to better study the structure of the gif file. Finally, I will elaborate on how the gif file is composed and how efficient it is. Manipulate this type of file.

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326879995&siteId=291194637