---hashing method of finding

Source: Internet
Author: User

There are many ways to find methods, such as: sequential lookups, binary lookups, block lookups, number-based lookups, and so on, but one common feature of these lookups is that they look for the I in A[i] in a comparative way, such as sequential lookups, by comparing each element in the array sequentially, and finally finding I, Binary find is only in comparison with some techniques, so that the comparison of this number is reduced, but, the principle is still compared, tree-based search is actually a different way of storage (linked list), and its principle is to find I by comparison.

Is there a way not to compare, but directly according to the given keyword and find the corresponding storage location? This is the core principle used by hashing Method!

Techniques used in hashing: hashing technology

Hashing is the establishment of a definite connection between the keyword and its corresponding storage location. F,f is called a hash function, which is stored in a contiguous space by hashing, which is what we call a hash table, just like us, we are keywords and have various attributes (gender, age, place of origin, etc.), We connect with someone with a social security number through some definite relationship.

The scope of use of the hashing method:

Hashing is suitable for a storage location where a keyword is stored, just like a person who has a unique DNA;

Not suitable for a one-to-many situation, such as, a class of 50 students, half of the boys half of the girls, we a boy or girl as a key word, corresponding to 25 cases, with the hash method is not appropriate;

Not suitable for finding the scope, for example, find this class 20--22 years old classmate;

Not suitable for finding the maximum or minimum value;

Conflict:

The conflict is two keywords corresponding to the same hash location, for how to deal with the conflict, put the following again.

How to construct a hash function:

1. Digital Analysis method


2. The method of square take

is to give a keyword, such as, 123, we take 123 square, get 15129, we can take 512 as the hash address.

3. Folding method


4. Residual remainder method (common method)



5. Pseudo-Random number method


The hash function is constructed, and the hash table can be drawn quickly, but we often find that the hash table is not what we expected (a value corresponds to a storage location), but sometimes multiple keywords correspond to the same storage location (see figure 8-10-6), which is what we call a conflict, The next question is how to resolve the conflict.

1. Open addressing method



2. Re-hash function method


3. Link Address method



4. Public overflow Zone law




Reference: "Big liar data Structure" geoscience.

---hashing method of finding

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.