I read about the hash table and open source advertising. If you want to insert keys: 18,32,44 into a hash table of size 13:
18 gets index 5 (18 modulus 13 = 5) 32 gets index 6 (32 modulus 13 = 6) 44 gets index 5 (44 modulus 13 = 5)
You will get a collision because there is already something in the index.
If you use linear research, you will do hashfunction = (key+i) modulus N where i = 0,1,2.. until you find an empty space in the hash table. Then 44 will be inserted at index 7.
What if you delete 32 and then want to delete 44. You start by looking at hashfunction(44)=5 - it was not 44, and then hashfunction(44 + 1) = 6 - empty. Then you might think that 44 is gone. How do you mark a place in the hash table that the place is not empty but does not contain a key, and that you should keep looking for 44 in the next index?
If you need to insert another key into index 6, then the key simply overwrites the โlabelโ in the hash table.
What could you use to indicate an index - it was the key here, but it was deleted, so you keep looking at the next index? You cannot just write null or 0, because then you think that the key has been deleted (null) or that the key with a value of 0 has overwritten 44.
source share