I am trying to understand the open addressing method. I refer to T. H. Cormen\'s book on this topic, which states that deletion is difficult in open addressing. I am completely
Assume hash(x) = hash(y) = hash(z) = i
. And assume x
was inserted first, then y
and then z
.
In open addressing: table[i] = x
, table[i+1] = y
, table[i+2] = z
.
Now, assume you want to delete x
, and set it back to NULL
.
When later you will search for z
, you will find that hash(z) = i
and table[i] = NULL
, and you will return a wrong answer: z
is not in the table.
To overcome this, you need to set table[i]
with a special marker indicating to the search function to keep looking at index i+1
, because there might be element there which its hash is also i
.