This commit is contained in:
krahets 2023-02-19 01:48:34 +08:00
parent 6bd1f46936
commit bb19b1d949
4 changed files with 2 additions and 2 deletions

View File

@ -1688,7 +1688,7 @@ G & = \{ V, E \} \newline
<p>「邻接表 Adjacency List」使用 <span class="arithmatex">\(n\)</span> 个链表来表示图,链表结点表示顶点。第 <span class="arithmatex">\(i\)</span> 条链表对应顶点 <span class="arithmatex">\(i\)</span> ,其中存储了所有与该顶点相连的顶点。</p> <p>「邻接表 Adjacency List」使用 <span class="arithmatex">\(n\)</span> 个链表来表示图,链表结点表示顶点。第 <span class="arithmatex">\(i\)</span> 条链表对应顶点 <span class="arithmatex">\(i\)</span> ,其中存储了所有与该顶点相连的顶点。</p>
<p><img alt="adjacency_list" src="../graph.assets/adjacency_list.png" /></p> <p><img alt="adjacency_list" src="../graph.assets/adjacency_list.png" /></p>
<p>邻接表仅存储存在的边,而边的总数往往远小于 <span class="arithmatex">\(n^2\)</span> ,因此更加节省空间。但是,因为在邻接表中需要通过遍历链表来查找边,所以其时间效率不如邻接矩阵。</p> <p>邻接表仅存储存在的边,而边的总数往往远小于 <span class="arithmatex">\(n^2\)</span> ,因此更加节省空间。但是,因为在邻接表中需要通过遍历链表来查找边,所以其时间效率不如邻接矩阵。</p>
<p>观察上图发现,<strong>邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率</strong>。比如当链表较长时可以把链表转化为「AVL 树」,从而将时间效率从 <span class="arithmatex">\(O(n)\)</span> 优化至 <span class="arithmatex">\(O(\log n)\)</span> ,还可以通过中序遍历获取有序序列;还可以将链表转化为 HashSet即哈希表将时间复杂度降低至 <span class="arithmatex">\(O(1)\)</span> </p> <p>观察上图发现,<strong>邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率</strong>。比如当链表较长时可以把链表转化为「AVL 树」,从而将时间效率从 <span class="arithmatex">\(O(n)\)</span> 优化至 <span class="arithmatex">\(O(\log n)\)</span> ,还可以通过中序遍历获取有序序列;还可以将链表转化为 HashSet即哈希表将时间复杂度降低至 <span class="arithmatex">\(O(1)\)</span></p>
<h2 id="914">9.1.4. 图常见应用<a class="headerlink" href="#914" title="Permanent link">&para;</a></h2> <h2 id="914">9.1.4. 图常见应用<a class="headerlink" href="#914" title="Permanent link">&para;</a></h2>
<p>现实中的许多系统都可以使用图来建模,对应的待求解问题也可以被约化为图计算问题。</p> <p>现实中的许多系统都可以使用图来建模,对应的待求解问题也可以被约化为图计算问题。</p>
<div class="center-table"> <div class="center-table">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 55 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.