Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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: 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:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started