mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-02 02:02:57 +08:00
deploy
This commit is contained in:
@@ -3382,7 +3382,7 @@
|
||||
<h1 id="63">6.3 哈希算法<a class="headerlink" href="#63" title="Permanent link">¶</a></h1>
|
||||
<p>在上两节中,我们了解了哈希表的工作原理和哈希冲突的处理方法。然而无论是开放寻址还是链地址法,<strong>它们只能保证哈希表可以在发生冲突时正常工作,但无法减少哈希冲突的发生</strong>。</p>
|
||||
<p>如果哈希冲突过于频繁,哈希表的性能则会急剧劣化。如图 6-8 所示,对于链地址哈希表,理想情况下键值对平均分布在各个桶中,达到最佳查询效率;最差情况下所有键值对都被存储到同一个桶中,时间复杂度退化至 <span class="arithmatex">\(O(n)\)</span> 。</p>
|
||||
<p><a class="glightbox" href="../hash_algorithm.assets/hash_collision_best_worst_condition.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="哈希冲突的最佳与最差情况" src="../hash_algorithm.assets/hash_collision_best_worst_condition.png" /></a></p>
|
||||
<p><a class="glightbox" href="../hash_algorithm.assets/hash_collision_best_worst_condition.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="哈希冲突的最佳与最差情况" class="animation-figure" src="../hash_algorithm.assets/hash_collision_best_worst_condition.png" /></a></p>
|
||||
<p align="center"> 图 6-8 哈希冲突的最佳与最差情况 </p>
|
||||
|
||||
<p><strong>键值对的分布情况由哈希函数决定</strong>。回忆哈希函数的计算步骤,先计算哈希值,再对数组长度取模:</p>
|
||||
|
||||
Reference in New Issue
Block a user