我有一个大小为8的哈希表,我想插入值(0, 1, 8, 9, 5, 33)。
我尝试了哈希函数,但出现了冲突,然后我尝试了双重哈希算法,但冲突仍然发生,如下所示:
哈希函数 = H1(k) = k % 8
双重哈希算法 = H2(k) = M - (k % M)
H1(0) = 0 % 8 = 0
H1(1) = 1 % 8 = 1
H1(8) = 8 % 8 = 0 -----> Needs double hashing ----> 7-(8 % 7)=7-1=6 (we forward 6 steps from the current position which is 0 and it will become 6).
H1(9) = 9 % 8 = 1----> Needs double hashing ---> 7 - (9%7)=7-2=5(we forward 5 steps from the current position which is 1 and it will become 6 again).
现在我被卡住了,不知道该怎么办。 注:我不想使用其他方法,只想使用双哈希。 非常感谢您的帮助。