mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-11 03:10:58 +00:00
deploy
This commit is contained in:
@@ -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. Complexity analysis<a class="headerlink" href="#2-complexity-analysis_1" title="Permanent link">¶</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>
|
||||
|
||||
Reference in New Issue
Block a user