Assume a hash table utilizes an array of 13 elements and tha
Assume a hash table utilizes an array of 13 elements and that collisions are handled by separate chaining. Considering the hash function is defined as: h(k)=k mod 13. i) Draw the contents of the table after inserting elements with the following keys: 32, 147, 265, 195, 207, 180, 21, 16, 189, 202, 91, 94, 162, 75, 37, 77, 81, 48.
To reduce the maximum number of collisions in the hash table described in Question 6 above, someone proposed the use of a larger array of 15 elements (that is roughly 15% bigger) and of course modifying the hash function to: h(k)=k mod 15. The idea was to reduce the load factor and hence the number of collisions.
Does this proposal hold any validity to it? If yes, indicate why such modifications would actually reduce the number of collisions. If no, indicate clearly the reasons you believe/think that such proposal is senseless.
Solution
# The following code provides some examples for using mathematical built-ins # Absolute value of 9 >>> abs(9) 9 # Absolute value of -9 >>> abs(-9) 9 # Divide 8 by 4 and return quotient, remainder tuple >>> divmod(8,4) (2, 0) # Do the same, but this time returning a remainder (modulo) >>> divmod(8,3) (2, 2) # Obtain 8 to the power of 2 >>> pow(8,2) 64 # Obtain 8 to the power of 2 modulo 3 ((8 **2) % 3) >>> pow(8,2,3) 1 # Perform rounding >>> round(5.67,1) 5.7 >>> round(5.67) 6.00