This commit is contained in:
krahets
2024-05-02 01:46:20 +08:00
parent 5e90519796
commit 23353e7960
324 changed files with 420 additions and 419 deletions
+2 -2
View File
@@ -3688,7 +3688,7 @@
<!-- Page content -->
<h1 id="93-graph-traversal">9.3 &nbsp; Graph traversal<a class="headerlink" href="#93-graph-traversal" title="Permanent link">&para;</a></h1>
<p>Trees represent a "one-to-many" relationship, while graphs have a higher degree of freedom and can represent any "many-to-many" relationship. Therefore, we can consider trees as a special case of graphs. Clearly, <strong>tree traversal operations are also a special case of graph traversal operations</strong>.</p>
<p>Both graphs and trees require the application of search algorithms to implement traversal operations. Graph traversal can be divided into two types: "Breadth-First Search (BFS)" and "Depth-First Search (DFS)".</p>
<p>Both graphs and trees require the application of search algorithms to implement traversal operations. Graph traversal can be divided into two types: <u>Breadth-First Search (BFS)</u> and <u>Depth-First Search (DFS)</u>.</p>
<h2 id="931-breadth-first-search">9.3.1 &nbsp; Breadth-first search<a class="headerlink" href="#931-breadth-first-search" title="Permanent link">&para;</a></h2>
<p><strong>Breadth-first search is a near-to-far traversal method, starting from a certain node, always prioritizing the visit to the nearest vertices and expanding outwards layer by layer</strong>. As shown in Figure 9-9, starting from the top left vertex, first traverse all adjacent vertices of that vertex, then traverse all adjacent vertices of the next vertex, and so on, until all vertices have been visited.</p>
<p><a class="glightbox" href="../graph_traversal.assets/graph_bfs.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Breadth-first traversal of a graph" class="animation-figure" src="../graph_traversal.assets/graph_bfs.png" /></a></p>
@@ -4814,7 +4814,7 @@ aria-label="Footer"
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright &copy; 2022-2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
Copyright &copy; 2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
</div>