How is this hash sensing method quadratic?

I have a problem with the difference between quadratic and linear sensing algorithms. When I read the conceptual explanations, I see that I ^ 2 have been repeatedly added to the last index. How are things going here? What would change linear sensing? From what I'm reading, the method below implements quadratic sensing.

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; } 
+4
source share
1 answer

Indexes are generated here:

 H // offset : 1 H + 1 // offset : 3 H + 4 // offset : 5 H + 9 // offset : 7 . . . 

Since n ^ 2 = 1 + 3 + 5 + ... + (n * 2 - 1) , this is actually the function H(n) = H + n ^ 2 , so this is quadratic sounding.

+5
source

Source: https://habr.com/ru/post/1479054/


All Articles