The hash function of the hash table, what are the conflict resolution methods

Source: Internet
Author: User

The 3 most commonly used hash functions:

1. Division hashing: By taking K divided by the remainder of M, to map the keyword K to one of the M slots, that is, the hash function is:

H (k) = k mod m

2. Multiplication hashing: First, the keyword K is multiplied by the constant A (0<a<1), and the fractional part of Ka is extracted, then, by multiplying the value by M, the bottom of the result (that is, the integer part) is taken. The hash function can be expressed as:

H (k) =⌊m (KA mod 1) ⌋

3. Global hashing method (Universal hashing)

There are two common ways to resolve conflicts:

1. Linking method (chaining): all elements that are hashed into the same slot are stored in a linked list. Each slot has a pointer to the head of the linked list that consists of all the elements that are hashed into the slot. If no such element exists, the pointer is empty. If the link method uses a doubly linked list, the worst-case run time for the delete operation is the same as the insert operation, which is O (1), while the average time for the next successful lookup requires θ (1+α). α is the filling factor.

2. Open addressing Method (openaddressing): All elements are stored in a hash table. Therefore, the case for dynamic collection size n is not greater than the hash table size, that is, the loading factor does not exceed 1. Otherwise, a hash table overflow may occur. There are three techniques commonly used to calculate the detection sequence in open addressing: linear detection, two detection, and dual detection.

The hash function of the hash table, what are the conflict resolution methods

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.