我有一个大小为 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 …Run Code Online (Sandbox Code Playgroud)