Home > Mobile >  Hash table and chaining method
Hash table and chaining method

Time:10-07

In my hash table each list is sorted (chaining method). 1.How this will affect the running time of the search for an existing key 2.How will this affect the running time of searching for a missing key? 3.How will this affect the search time for adding and deleting a key?

CodePudding user response:

1.How this will affect the running time of the search for an existing key.

Not so much, because the collision is rarely to happen.

With N is the size of your hash table, M is the number of collision.

M is often too small ( from 0-50 ), so the speed is not changed so much.

In case M is too large and near N, in this situation, we have an bad hashing algorithm and it should be improved.

The worst case M=N if you have an terrible hashing algorithm, so you have an binary search with complexity O(Log N).

The benefits of hashtable is destroyed. The degradation O(1) -> O(Log N)

So we should avoid it anyway.

2.How this will affect the running time of the search for an missing key.

The same answer with 1. M is often so small, if not, rewrite your hashing algorithm.

  • Related