8.7 hash table)

Source: Internet
Author: User

For index search or continuous table search, you must compare keywords and search values. Do you need to compare them? You can use keywords to obtain the address corresponding to the keywords, this is the hash query.

Storage location = F (keyword );

The hash technique establishes a definite correspondence relationship F between the storage location of the record and Its keywords, so that each key corresponds to a storage location F (key );

The corresponding relationship F is called a hash function. Hash technology is used to store records in a continuous space. This continuous space is called a hash table or a hash table. The record location corresponding to the keyword is called the hash address.

Conflict: If two keywords key1! = Key2, but Fkey1) = f (key2). This phenomenon is called conflict and key1 and key2 are called synonyms of this hash function.

 

8.7.1 construction of Hash Functions

How to evaluate a good hash function

1) Simple computing

2) scattered addresses are evenly distributed, rather than distributed on a few addresses.

1. Direct addressing.

2. Digital analysis.

3. China and France.

4. Folding Method.

5. Remove the remaining parts.

F (key) = key mod pp <= m)

Mod indicates the modulo operation.

Generally, p is the minimum prime number that is less than or equal to the table length.

6. Random Number method, specifically the pseudo-random number method.

 

8.7.2 how to handle hash conflicts

If two keywords key1 are found after the hash function is used! = Key2, but f (key1) = f (key2) exists. What should I do when there is a conflict.

1. Open address Method

If a conflict occurs, search for the next empty hash address. As long as the hash address is large enough, the empty hash address can always be found and the record is saved.

F1 (key) = (f (key) + d1) mod m (d1 = 1, 2, 3, 4 ...... m-1)

Low search efficiency leads to accumulation.

2. link address Method

If there is a conflict or not, add a header pointer to the hash list and connect it to the end of the conflict with it. If there is a conflict between keyword 3 and keyword 6, it must exist in address 9, it can be designed in this way.

Address 9: 3 Data Pointer -----> 6 data NULL

 

This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1282378

Related Article

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.