Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Improve my Hashing Function C++ I have the following hashing function : int hash

ID: 660969 • Letter: I

Question

Improve my Hashing Function C++

I have the following hashing function :

int hash(string str)


{
   int sum = 0;
   for(int i = 0; i < str.length(); i++)
       sum += (str[i] - '0');
       sum += str.length();
       return (sum * 31) % SIZE;
}

The function recieved an string input then calculates the total ascii value + length of string then * 31 % tablesize

This function should return the same hash value if entered book or koob .

Currently, I recieve plenty of collisions in a table size less than 400

I wan to know if you can improve it to have less collisions .

Please help

Thank you

Explanation / Answer

using namespace std; #include #include #include void convertToASCII(string letter) { for (int i = 0; i