I was looking through the final exam on my data structures, and last year I came across a question. Working on it over the past three hours, I still could not figure out how to solve it, with the exception of trial and error. Here's the question:
"Suppose the size of your hash table is 31, the constant g is also 31, and you use the following hash code
int hash = 0;
int n = s.length();
for (int i = 0; i < n; i++)
hash = g * hash + s.charAt(i);
and that a separate chain is used to resolve conflicts. List five different names that will contain the hash in the same place in the table. "
I think that to solve this problem there should be some tricks, possibly related to the modulo operator, given the size of the hash table 31, which coincides with the constant g. Sorry if I like this, but I am not asking for code or anything else, just some thoughts / tips on this. Any comments are greatly appreciated. Thanks
source
share