1

For hashtables, as is familiar we first compute a hashfunction. Then we need to take care of collisions; cases when two or more keys to be inserted hash to the same index. Two methods of doing this include separate chaining and linear probing. My question is once again, which method is less costly when it comes to deletion?

My initial idea is that, if the clusters in linear probing are large, and we want to delete some key early in the cluster, it may become costly to reinsert all the keys to the right of the deleted key.

Is this statement, if valid at all, reason enough to assume that separate chaining is more efficient at deletion than linear probing?

0jnats3
  • 85
  • 1
  • 7

1 Answers1

1

In the case of linear probing, deletion would affect searches for other keys that have a hash value earlier than the emptied cell, but those are stored in a position later than the emptied cell. The emptied cell would cause those searches to incorrectly report that the key is not present. So, when a cell is emptied, it is necessary to search forward through the following cells of the table until finding either another empty cell or a key that can be moved to the cell and the process needs to go on till an empty cell found.

But the case of separate chaining we just need to delete the value from the linked list and deleting the value from a linked list is much easier than the above process in case of linear probing.

Amit Bera
  • 7,075
  • 1
  • 19
  • 42