简体   繁体   English

Hash表及链接方法

[英]Hash table and chaining method

In my hash table each list is sorted (chaining method).在我的 hash 表中,每个列表都已排序(链接方法)。 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? 1.这将如何影响搜索现有密钥的运行时间 2.这将如何影响搜索丢失密钥的运行时间? 3.How will this affect the search time for adding and deleting a key? 3.这将如何影响添加和删除键的搜索时间?

1.How this will affect the running time of the search for an existing key. 1.这将如何影响搜索现有密钥的运行时间。

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.其中N是你的hash表的大小,M是碰撞次数。

M is often too small ( from 0-50 ), so the speed is not changed so much. M 通常太小(从 0-50 ),所以速度变化不大。

In case M is too large and near N, in this situation, we have an bad hashing algorithm and it should be improved.如果 M 太大并且接近 N,在这种情况下,我们的散列算法不好,应该改进。

The worst case M=N if you have an terrible hashing algorithm, so you have an binary search with complexity O(Log N).如果你有一个糟糕的散列算法,那么最坏的情况 M=N,所以你有一个复杂度为 O(Log N) 的二进制搜索。

The benefits of hashtable is destroyed. hashtable 的好处被破坏了。 The degradation O(1) -> O(Log N)退化 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. 2.这将如何影响搜索丢失密钥的运行时间。

The same answer with 1. M is often so small, if not, rewrite your hashing algorithm.与1相同的答案。M通常很小,如果不是,请重写您的哈希算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM