I'm working through some old exam papers and came across the following:
Demonstrate how a closed address hashing algorithm works using the data set
{4, 2, 12, 3, 9, 11, 7, 8, 13, 18}
as an input example.Assume the lenght of the array is initially 7. You should demonstrate:
i. how the hash table is built, step-by-step ii. how a search on a hash table can be acheived in O(1) time.
Now, given that the array is initially set to 7, the largest hash function I can use is n mod 7
, as there are are more elements to be inserted than the size of the array, the array must be resized.
I am assuming that the hash function remains the same after resizing?
Regarding the second part, how can O(1)
search be achieved if many elements hash to the same value? Surely, I need to sequentially through clustered elements in the array?
Is this hypothesis correct?