a to d, 2 points each.
Here are four attempts to define a hash function. For each of them say
whether they are good or bad, and briefly explain why.
C
A unsigned int Ahaah (steing al
Tunsigned int h 137
unsigned int ns.length
for (int i = 0; i < 1+12
h += s[1];
return size: 1
B unsigned int Shashietring =)
I unsigned int h = 63443;
unsigned int
length:
for (int & C; i < mi +1
h[31:
return size; }
i.
ii.
iii.
iv.
Define in C++:
signed int Chash(strings)
(unsigned int h 752711
ints.length();
for (int i=0; i hh 159 + 5111; return size; D in Dhash(strings) (nth-75291: ants.length(); e, 25 points. A CircusAnimal is to be represented as an object with the following members: Two strings, for its name and species. Two ints, for its purchase price and the number of children it has eaten. The Circus Database Manager has decided that the CircusAnimal objects must be stored in a Hash Table organised so that the details of an animal can be found quickly if its name and species are known. Fortunately, no two animals of the same species ever have the same name, and no circus animals. have a zero price, not even the clowns. for (int i = 0; i < / 111 hh169 11: if it < 0) hh/ return hi I The classes or structs required for the hash table, A constructor for the hash table. A method void add(string, string, int, int) for adding a new animal, and A method double efficiency(string, string which when provided with the name and species of an animal, return its efficiency. The efficiency of a circus animal is of course the number of children it has eaten divided by its price. You do not need to write the hash function, just assume that a good one has been provided. Example of use: f hashtable H; H.add("timmy", "tiger", 7500, 61: H.add("priscilla", "dancing horse", 800, 2); H.add("stubbo", "clown", 45, 0); cout << H.efficiency ("cimmy", "tiger"); // prints 0.0008
Fig: 1