Question: Answer the below - also the functions are included int hashFunction1(const char* key) { int r = 0; for (int i = 0; key[i] !=

Answer the below - also the functions are included

int hashFunction1(const char* key)

{

int r = 0;

for (int i = 0; key[i] != '\0'; i++)

{

r += key[i];

}

return r;

}

int hashFunction2(const char* key)

{

int r = 0;

for (int i = 0; key[i] != '\0'; i++)

{

r += (i + 1) * key[i];

}

return r;

}

int hashMapSize(HashMap* map)

{

// FIXME: implement

return map->size;

}

float hashMapTableLoad(HashMap* map)

{

// FIXME: implement

return (double)map->size / (map->capacity);

}

int hashMapEmptyBuckets(HashMap* map)

{

// FIXME: implement

int count = 0;

for (int i = 0; i < map->capacity; i++) {

if (map->table[i] == 0) {

count++;

}

}

return count;

}

1. Give an example of two words that would hash to the same value using hashFunction1 but would not using hashFunction2.

2. Why does the above observation make hashFunction2 superior to hashFunction1?

3. When you run your program on the same input file once with hashFunction1 and once with hashFunction2, is it possible for your hashMapSize function to return different values?

4. When you run your program on the same input file once with hashFunction1 and once with hashFunction2, is it possible for your hashMapTableLoad function to return different values?

5. When you run your program on the same input file once with hashFunction1 and once with hashFunction2, is it possible for your hashMapEmptyBuckets function to return different values?

6. Is there any difference in the number of empty buckets when you change the table size from an even number like 1000 to a prime like 997?

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!