Question & Answer: Answer the below – also the functions are included…..

Answer the below – also the functions are included

int hashFunction1(const char* key)

{

int r = 0;

for (int i = 0; key[i] != ‘’; i++)

{

r += key[i];

}

return r;

}

int hashFunction2(const char* key)

{

int r = 0;

for (int i = 0; key[i] != ‘’; 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?

Expert Answer

 

Question & Answer: Answer the below - also the functions are included..... 1Question & Answer: Answer the below - also the functions are included..... 2Question & Answer: Answer the below - also the functions are included..... 3

Still stressed from student homework?
Get quality assistance from academic writers!