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.