Question: Q 6 Your turn to Hash! 5 Points Grading comment: Assume you are hashing a set ( unknown length ) of randomly generated Strings, into
Q Your turn to Hash!
Points
Grading comment:
Assume you are hashing a set unknown length of randomly generated Strings, into a HashTable with a a size of this means your HashTable has buckets You can also assume that Strings are iterable and Characters utilize the Java native hash function.
Examine the two hashCode implementations below. In general, which hashCode option will result in a greater number of collisions for all Strings? Justify your answer in sentences describing how each hashCode may generate a range of possible hashCode values.
Assume that when we call this in our hash functions, we are referring to each String object we are hashing.
Option :
This code utilizes Java's implementation of hashCode for Characters which returns the unique int value associated with each character based on its assigned ASCII value. Ex: a returns A returns
public int hashCode
Iterator iterator this.iterator;
int result ;
int i ;
while iteratorhasNext
result iterator.nexthashCode;
i;
return result;
Option :
This code utilizes Java's implementation of hashCode for Strings which is the following value is an array of the characters within the array:
Javas String hashCode implementation
public static int hashCodebyte value
int h ;
int length value.length;
for int i ; i length; i
h h getCharvalue i;
return h;
public int hashCode
return this.hashCode
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
