Question: //main.cpp #include #include #include using namespace std; int hashFunction(string s, int M) { // Your Code Here //hash function to sum up the ASCII characters

 //main.cpp #include #include #include using namespace std; int hashFunction(string s, int

//main.cpp

#include

#include

#include

using namespace std;

int hashFunction(string s, int M) {

// Your Code Here

//hash function to sum up the ASCII characters of the letters of the string

}

int countCollisions (int M, vector inputs) {

int collisions = 0;

// Your Code Here

return collisions;

}

int main() {

vector inputs {"hi", "i", "richa", "TA", "CS225","fi","hello","weare",

"always","there","for","you","valspar","ri","sh","tg","uf","the", "frogurt", "is",

"also", "cursed","Whats", "your", "name", "Homer", "Simpson", "What", "is", "favorite",

"team", "The", "Isotopes", "I", "like", "too"};

for (int i=1; i

cout\t"

}

return 1;

}

The Problem Task 1 Complete the function simple Hash Function in main.cpp that accepts a string and the size of the hash table 'int M'. So, basically it takes the string, performs some computation on it and then returns an index in the range 0 to (M-1). A simple implementation is to sum the ASCII values of the letters in a string. If the hash table size M is small compared to the resulting summations, then this hash function should do a good job of distributing strings evenly among the hash table slots, because it gives equal weight to all characters in the string. This is an example of the folding approach to designing a hash function. Note that the order of the characters in the string has no effect on the result. Task 2: Now write the function int countCollisions (int M, vector inputs) lt takes the size of the hash table as input and a vector of strings. It goes over all the input strings, performs the above 'simpleHashFunction' over it and counts the total number of collisions at each index in the hash table (index ranging from 0 to M-1). In the main function, there is a code to test how the number of collisions change on chaging the size of the hash table. We vary the size from 1 to 11 Example output: performing hash on the inputs with array size 1 J> 34 32 performing hash on the inputs with array size 3 30 AND SO ON Compile and Test A complete Makefile and a main. Cpp file containing one simple test has been provided for you. To compile and run, run: make /main

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!