Can some one explain
Given a hash table array of size N=11., and using a hash function –
h(x) = 3 x + 7 mod NTogether with linear probing, the following sequence of operations are
performed:insert 5, insert 15, insert 4, insert 8, insert 7, insert 12
What is the final state of the hash table?
By my logic
h(5) = (3*5) + (7 mod 11) = 15 + 7 = 22 so place in table[0]
h(15) = (3*15) + (7 mod 11) = 45 + 7 = 52 so place in array[0]..cant so put in table[1]
etc.
But apparently my method is wrong. – e.g. h(15) places 15 in table[8]
What have I failed to account for?
EDIT:
Forgot to mod 11 the answer! Simple mistake.
h(5) = ((3*5) + 7) mod 11 = 15 + 7 = 22 -> 22 mod 11 = 0 so place in table[0]
h(15) = ((3*15) + 7) mod 11 = 45 + 7 = 52 -> 52 mod 11 = 8 so place in array[8]
I think your hash function should be (3x+7) mod N, not 3x + (7 mod N).