假设我有一个哈希表arr [1..n],一组键k1,k2,k3(密钥的数量)等等.哈希函数h(k)
h(k)取输入k并给出输出i作为arr [i]的索引.
现在在哈希的线性探测概念中,让我们考虑一下场景.
1> let k1=101 and h(k)=i=5, then k1(101) is stored in arr[5]
2> let k2=102 and h(k)=i=6 then k1(102) is stored in arr[6]
3>Now again k3=101 and h(k)=i=5 then by linear probing it will go one
step ahead(i=i+1) and check a[i](a[6]) is free or not, since a[6] is not free
so we repeat again (i=i+1) and check a[i](a[7]) is free or not, since a[7] is free
so k3(101) is again inserted at arr[7].
Run Code Online (Sandbox Code Playgroud)
现在arr [5]和arr [7]可能是重复的,它们属于同一个键.
哈希表是否允许重复?我的理解是否正确.
如果我错了,请核实我
| 归档时间: |
|
| 查看次数: |
3848 次 |
| 最近记录: |