Question
** Please help me out, I'm trying to study for my final and this question is a practice example to prepare myself for the final **
Problem 1 Suppose we're doing hashing with keys of type String. Each of the following hash functions is bad. For each, explain what is wrong with it. Assume that your hash table is an array with indices 0 through HASHSIZE-1. Note: all of the functions return a value in the correct range and do not generate any run-time errors. Hash function 1 Assume that the string has at least 2 characters public static int hash (String key) return (key charAt (0) key. charAt (1) key. charAt (key length ()-1)) HASHSIZE Hash function 2. Reminder: Random is the class for generating random numbers nextInt (n) returns a random number in the range [0 n-11 public static int hash (String key) Random rand new Random int result 0; for (int i 0 i K key. length i++) return result rand.nextInt (37) key.charAt (i) return result HASHSIZE;
Explanation / Answer
it print 1->2->3->1->2->3->1->2->3-> and so on. its a circular Link list