Description
The purpose of this challenge is to implement a rudimentary hashing function.
Requirements
- Acquire a collection of words in a text file, enable1.txt
- Open the file and observe that it contains all the words in the English Language, all in lower case
- Create a rudimentary hash function int calc_hash(string word) that will take a word and
- Convert each letter to its positional value of a = 1, b = 2, y = 25, z = 26, etc
- The hash function will calculate the hash sum for the word as the sum total of each letter’s index value. For example, ‘aa’ = 2, ‘writer’ = 93
- Create an integer array of 320 elements, int collisions[320]. This array will keep track of the number of collisions for each of the indexes. For example, the word ‘writer’ will hash to 93, as will the word ‘zucchini’…when these words (writer, zucchini) are read, you will update the count at
collisions[93]. Each word will hash to a value. Keep track of the number of collisions for all the words in enable1.txt. Make sure that your array is initialized to 0 in the beginning. - All the words in this text file will create hash values between 1 and 319
- Display the contents of the collision table to the screen, one array element per line.
- Display the hash value that generated the most collisions
- Display the largest number of collisions.
- As an additional challenge: Instead of the hash function given in step 2, can you make a better one that will create fewer, or much fewer, collisions? Increase the array as needed for your implementation. The goal would be to find a hash function that generates the fewest collisions.
CATALOG ID: CPP-CHAL00054
Print Requirements