Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Compare value orientations among cultures

Answered: 1 week ago