collisions
Task. Instead of using the default hashCode method to each key, create a hash function applying the folding method.
Within your hash function
Split the string into 3 sub-strings, based from the reg-ex "-"
Parse your sub-strings to Integer and add (folding method)
Parse the summed value to String
Initialize an int variable for your hash to 0
Loop to each character index of the String
Apply the general formula for hashing: hash=31*hash+character in that index position;
Append & 0xFFFFFFF to it to make the resulting hash positive
Convert the hash to index of tablesize=20 using the % operator
Return hash
What index has the most occurrence of collisions?
Trending now
This is a popular solution!
Step by step
Solved in 3 steps