I am having some understanding problem with Hashing concept as follows:
Suppose, I have implemented hash table(1-D array, say A[100]) having keys as numbers. I have one simple hash function H(Key) % Table_Size, which will return target index into the hash table(while accessing value associated with this particular key).
Suppose, I want to store 0(key) into the table. When I pass this key to H(hash function), it returns random index, say 25.
There are 2 possibilities for this location in array A(having index 25):
- A[25] contains some key other than 0, as already been stored(previously)
- A[25] contains 0
First possibility has collision and it is easily identifiable(because current key:0 and already stored key:k are different), so no problem in first one.
But, for second one, how would I know weather there is a collision or not ?
As long as I know, hash table or array would be part of main memory. Suppose A[25] is stored into memory location 500.
How would I know weather this location(500) is actually empty or has been already filled by some other key ?
What status or value of memory cells represents EMPTY or NULL or UNUSED location ?
And, what if I want to store 0 as a key into this location doing collision check ?
I am currently assuming that if any memory location is EMPTY or NULL or UNUSED, then it would be in RESET state(all cells are 0's). Is this true ?
It may be silly question but I am wondering how to check collision in such cases.
--
Thanks in advance!! (Hitein, Hyderabad)