This commit is contained in:
krahets
2023-04-09 04:35:05 +08:00
parent fc4021ea99
commit 32b9491b24
249 changed files with 1523 additions and 1269 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File

@@ -1809,13 +1809,13 @@
<p>链式地址下,哈希表的操作方法包括:</p>
<ul>
<li><strong>查询元素</strong>:输入 key ,经过哈希函数得到数组索引,即可访问链表头点,然后遍历链表并对比 key 以查找目标键值对。</li>
<li><strong>添加元素</strong>:先通过哈希函数访问链表头点,然后将点(即键值对)添加到链表中。</li>
<li><strong>删除元素</strong>:根据哈希函数的结果访问链表头部,接着遍历链表以查找目标点,并将其删除。</li>
<li><strong>查询元素</strong>:输入 key ,经过哈希函数得到数组索引,即可访问链表头点,然后遍历链表并对比 key 以查找目标键值对。</li>
<li><strong>添加元素</strong>:先通过哈希函数访问链表头点,然后将点(即键值对)添加到链表中。</li>
<li><strong>删除元素</strong>:根据哈希函数的结果访问链表头部,接着遍历链表以查找目标点,并将其删除。</li>
</ul>
<p>尽管链式地址法解决了哈希冲突问题,但仍存在一些局限性,包括:</p>
<ul>
<li><strong>占用空间增大</strong>,由于链表或二叉树包含点指针,相比数组更加耗费内存空间;</li>
<li><strong>占用空间增大</strong>,由于链表或二叉树包含点指针,相比数组更加耗费内存空间;</li>
<li><strong>查询效率降低</strong>,因为需要线性遍历链表来查找对应元素;</li>
</ul>
<p>为了提高操作效率,<strong>可以将链表转换为「AVL 树」或「红黑树」</strong>,将查询操作的时间复杂度优化至 <span class="arithmatex">\(O(\log n)\)</span></p>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -1778,8 +1778,8 @@
<ol>
<li><strong>无序数组</strong>:每个元素为 <code>[学号, 姓名]</code> </li>
<li><strong>有序数组</strong>:将 <code>1.</code> 中的数组按照学号从小到大排序;</li>
<li><strong>链表</strong>:每个点的值为 <code>[学号, 姓名]</code> </li>
<li><strong>二叉搜索树</strong>:每个点的值为 <code>[学号, 姓名]</code> ,根据学号大小来构建树;</li>
<li><strong>链表</strong>:每个点的值为 <code>[学号, 姓名]</code> </li>
<li><strong>二叉搜索树</strong>:每个点的值为 <code>[学号, 姓名]</code> ,根据学号大小来构建树;</li>
</ol>
<p>各项操作的时间复杂度如下表所示(详解可见<a href="https://www.hello-algo.com/chapter_tree/binary_search_tree/">二叉搜索树章节</a>)。无论是查找元素还是增删元素,哈希表的时间复杂度都是 <span class="arithmatex">\(O(1)\)</span>,全面胜出!</p>
<div class="center-table">