[C++] are there any issues with the following hash functions? A. hash table has
ID: 3716522 • Letter: #
Question
[C++] are there any issues with the following hash functions?
A. hash table has size 10,000. search keys are integers in range 0..999,999. the hash function is:
• h(key) = (key * rand()) % 10,000, where rand() is a function that returns a random float between 0 and 1 B.
hash table has size 2048. search keys are plant varieties. the hash function is:
• h(key) = (position in alphabet of first letter of key) % 2048
•h(key) = (sum of positions in alphabet of key's letters) %
2048
• hash table has size 10,000. search keys are integers in range 0..9,999. the hash function is defined by the C++
function:
int hashIndex(int x)
{
for (int i=1; i<=10000; i++)
x = (x*x) % 10000;
return x;
}
Explanation / Answer
Hash function is used to insert and access elements from the hashtable, and hash function should generate the same value for a particular key..whenever we call it
given hash functions:
h(key) = (key * rand()) % 10,000
here...this hash function doesn't generate the same value for the particular key....because of random funciton....it will give different values...by that...we may not access or data
h(key) = (position in alphabet of first letter of key) % 2048
this function generates same value every time for a particular....but many keys may be mapped at same location
h(key) = (sum of positions in alphabet of key's letters) %
2048
this function generates same value every time for a particular....but many keys may be mapped at same location
int hashIndex(int x)
{
for (int i=1; i<=10000; i++)
x = (x*x) % 10000;
return x;
}
this function generates same value every time for a particular..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.