Question: Please write the following program in c Define a function hash_string which takes a string (a char *) as a parameter and returns an unsigned
Please write the following program in c
Define a function hash_string which takes a string (a char *) as a parameter and returns an unsigned integer between 0 and SIZE -1, by hashing the string. You are free to choose your own hash algorithm, but here is a simple one you can use:
o Define an unsigned integer variable hash and initialize it to 1.
o In a loop that iterates over each character in the string, set hash equal to (hash * 7) + c in each iteration of the loop, where c is the current character. Since a char is just an 8-bit number, so its fine to do arithmetic on it.
o Return the value of hash mod SIZE (where % is the mod operator)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
