I have a string anna
, where values of chars in the string are a = 1, n = 14 ( You can compute the value of other chars like ( char - 96 )
and hash function which looks like :
int hashCode( string s ) // s = "anna";
{
k = 0;
for ( int i = 0; i < s.length(); i++ )
k = ( 7 * k + 3 * s[i] ) % 61;
return k;
}
How do I find a string of length 3 where collision happens ( something smart )? The only way that comes to my mind is to calculate k
of anna
which is 29
and then somehow think of another string of length 3 which gives 29
.