Open addressing method for linear detection to handle Hash Storage conflicts

Source: Internet
Author: User

Today, I saw a basic question, recorded the problem solving process, and shared it with you.

1. Question:

A linear table (,) is known. If H (K) = K % 6 is used to calculate the hash address for hashed storage, if the open addressing method of linear detection is used to handle conflicts, the average length of the search in the hash is ().

 

A. 1.5 B. 1.7 C. 2 d. 2.3

 

2. Problem Solving Process:

(1) Computing H (k): 38% 6 = 2 25% 6 = 1 74% 6 = 2 63% 6 = 3 52% 6 = 4 48% 6 = 0

(2) Address:

Address: 0 1 2 3 4 5

1. 1st elements in a linear table (38): 38 (1st no conflict)

2. 2nd elements in a linear table (25): 25 (1st no conflict)

3. 3rd elements in a linear table (74): 74 (1st conflicts, address + 1)

4. 3rd elements in a linear table (74): 74 (2nd no conflict)

5. 4th elements in a linear table (63): 63 (1st conflicts, address + 1)

6. 4th elements in a linear table (63): 63 (2nd no conflict)

7. 5th elements in a linear table (52): 52 (1st conflicts, address + 1)

8. 5th elements in a linear table (52): 52 (2nd no conflict)

9. 6th elements in a linear table (48): 48 (1st no conflict)

After the above addressing process, each element in a linear table has a unique address.

3. Results

The six elements in a linear table are fixed nine times,

The average length of a search in the hash is 9/6 = 1.5.

 

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.