Hash Table: Why deletion is difficult in open addressing scheme

后端 未结 3 1615
时光说笑
时光说笑 2021-01-31 04:18

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

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 05:11

    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.

提交回复
热议问题