Question: In c++ in visual studio as mentioned in the question . Consider the following hash function, similar to hash functions discussed in class. unsigned Hash(

In c++ in visual studio as mentioned in the question .

Consider the following hash function, similar to hash functions discussed in class.

unsigned Hash( const string & key, const int h_size )

{

unsigned int value = 0;

for ( int i=0; i

value = (value + key[i])*16;

return value % h_size;

}

(a) What is the hash function? Write it in a mathematical expression.

(b) Is this a good hash function when h_size = 64? Why or why not?

(c) Suppose the statement in the for loop is changed to value = value*31 + key[i]; and h_size = 71. Is this new hash function better than the above hash function or not?

Justify your answer by coding and testing the two hash functions in (b) and (c) on sample strings to verify the difference in the quality of the hash functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!