我在区分二次和线性探测算法时遇到问题。当我阅读概念性解释时,我看到 I^2 被反复添加到最后一次尝试的索引中。这是怎么回事?线性探测会把它变成什么?从我正在阅读的内容来看,下面的方法实现了二次探测。
private int findPosQuadratic( AnyType x )
{
int offset = 1;
int currentPos = myhash( x );
while( array[ currentPos ] != null &&
!array[ currentPos ].element.equals( x ) )
{
currentPos += offset; // Compute ith probe
offset += 2;
if( currentPos >= array.length )
currentPos -= array.length;
}
return currentPos;
}