This commit is contained in:
krahets
2024-05-07 16:35:27 +08:00
parent 885877f818
commit 5a2b679c34
13 changed files with 349 additions and 349 deletions
+1 -1
View File
@@ -4085,7 +4085,7 @@
<div class="admonition question">
<p class="admonition-title">Is the sequence of depth-first traversal unique?</p>
<p>Similar to breadth-first traversal, the order of the depth-first traversal sequence is also not unique. Given a certain vertex, exploring in any direction first is possible, that is, the order of adjacent vertices can be arbitrarily shuffled, all being part of depth-first traversal.</p>
<p>Taking tree traversal as an example, "root <span class="arithmatex">\(\rightarrow\)</span> left <span class="arithmatex">\(\rightarrow\)</span> right", "left <span class="arithmatex">\(\rightarrow\)</span> root <span class="arithmatex">\(\rightarrow\)</span> right", "left <span class="arithmatex">\(\rightarrow\)</span> right <span class="arithmatex">\(\rightarrow\)</span> root" correspond to preorder, inorder, and postorder traversals, respectively. They showcase three types of traversal priorities, yet all three are considered depth-first traversal.</p>
<p>Taking tree traversal as an example, "root <span class="arithmatex">\(\rightarrow\)</span> left <span class="arithmatex">\(\rightarrow\)</span> right", "left <span class="arithmatex">\(\rightarrow\)</span> root <span class="arithmatex">\(\rightarrow\)</span> right", "left <span class="arithmatex">\(\rightarrow\)</span> right <span class="arithmatex">\(\rightarrow\)</span> root" correspond to pre-order, in-order, and post-order traversals, respectively. They showcase three types of traversal priorities, yet all three are considered depth-first traversal.</p>
</div>
<h3 id="2-complexity-analysis_1">2. &nbsp; Complexity analysis<a class="headerlink" href="#2-complexity-analysis_1" title="Permanent link">&para;</a></h3>
<p><strong>Time complexity</strong>: All vertices will be visited once, using <span class="arithmatex">\(O(|V|)\)</span> time; all edges will be visited twice, using <span class="arithmatex">\(O(2|E|)\)</span> time; overall using <span class="arithmatex">\(O(|V| + |E|)\)</span> time.</p>