hash table

Like dictionaries, hash tables are generalized linear-like tables indexed by keys. The difference is that the key code key in the dictionary index item directly corresponds to the storage location address of the record (or table item), and the records (or table items) in the dictionary need to be retrieved by sequential search or binary search. The hash table is the storage location address of the record (or table entry) and its key. A corresponding functional relationship is established between the key value address=hash(key) , so that each key is a unique storage location in the structure. Corresponding. When looking up a record (or table item), first calculate the addres=hash(key), and take the record (or table item) at the address position in the structure. If the keys are the same, the search is successful. When storing records (or table items), address=hash(key) is also calculated, and stored in the address position when storing records (or table items). This method is called a hash method, and the function used in the hash method is a hash function. The table or structure constructed in this way is the hash table.

The problem is: different keywords may have the same hash value calculated by the hash function. If another element already exists (with the same hash value) when one element is inserted, then a conflict has occurred and the conflict must be resolved. There are generally two ways to resolve conflicts:

1) Separation link method: The hash table T adopts the separation link technology, that is, the keywords with the same hash function value are strung together into a linked list (using an adjacency list).

2) Open addressing method: The data structure of the hash table T is generally a one-dimensional array, and the hash function is directly used for addressing. If there is a conflict, try to select another cell until an empty cell is found. The hash function is generally designed according to the linear detection method or the quadratic linear detection method.

Example: poj3349 poj1840 uva246 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324961960&siteId=291194637