This commit is contained in:
krahets 2023-04-18 23:09:52 +08:00
parent 7924e697f4
commit a7acf4398a
14 changed files with 40 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View file

@ -2528,7 +2528,45 @@
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>使用循环一样可以实现前、中、后序遍历,但代码相对繁琐,有兴趣的同学可以自行实现。</p>
<p>我们也可以仅基于循环实现前、中、后序遍历,有兴趣的同学可以自行实现。</p>
</div>
<p>递归过程可分为“递”和“归”两个相反的部分。“递”表示开启新方法,程序在此过程中访问下一个节点;“归”表示函数返回,代表该节点已经访问完毕。如下图所示,为前序遍历二叉树的递归过程。</p>
<div class="tabbed-set tabbed-alternate" data-tabs="3:11"><input checked="checked" id="__tabbed_3_1" name="__tabbed_3" type="radio" /><input id="__tabbed_3_2" name="__tabbed_3" type="radio" /><input id="__tabbed_3_3" name="__tabbed_3" type="radio" /><input id="__tabbed_3_4" name="__tabbed_3" type="radio" /><input id="__tabbed_3_5" name="__tabbed_3" type="radio" /><input id="__tabbed_3_6" name="__tabbed_3" type="radio" /><input id="__tabbed_3_7" name="__tabbed_3" type="radio" /><input id="__tabbed_3_8" name="__tabbed_3" type="radio" /><input id="__tabbed_3_9" name="__tabbed_3" type="radio" /><input id="__tabbed_3_10" name="__tabbed_3" type="radio" /><input id="__tabbed_3_11" name="__tabbed_3" type="radio" /><div class="tabbed-labels"><label for="__tabbed_3_1">&lt;1&gt;</label><label for="__tabbed_3_2">&lt;2&gt;</label><label for="__tabbed_3_3">&lt;3&gt;</label><label for="__tabbed_3_4">&lt;4&gt;</label><label for="__tabbed_3_5">&lt;5&gt;</label><label for="__tabbed_3_6">&lt;6&gt;</label><label for="__tabbed_3_7">&lt;7&gt;</label><label for="__tabbed_3_8">&lt;8&gt;</label><label for="__tabbed_3_9">&lt;9&gt;</label><label for="__tabbed_3_10">&lt;10&gt;</label><label for="__tabbed_3_11">&lt;11&gt;</label></div>
<div class="tabbed-content">
<div class="tabbed-block">
<p><img alt="preorder_step1" src="../binary_tree_traversal.assets/preorder_step1.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step2" src="../binary_tree_traversal.assets/preorder_step2.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step3" src="../binary_tree_traversal.assets/preorder_step3.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step4" src="../binary_tree_traversal.assets/preorder_step4.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step5" src="../binary_tree_traversal.assets/preorder_step5.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step6" src="../binary_tree_traversal.assets/preorder_step6.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step7" src="../binary_tree_traversal.assets/preorder_step7.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step8" src="../binary_tree_traversal.assets/preorder_step8.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step9" src="../binary_tree_traversal.assets/preorder_step9.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step10" src="../binary_tree_traversal.assets/preorder_step10.png" /></p>
</div>
<div class="tabbed-block">
<p><img alt="preorder_step11" src="../binary_tree_traversal.assets/preorder_step11.png" /></p>
</div>
</div>
</div>
<h3 id="_4">复杂度分析<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h3>
<p><strong>时间复杂度</strong>:所有节点被访问一次,使用 <span class="arithmatex">\(O(n)\)</span> 时间,其中 <span class="arithmatex">\(n\)</span> 为节点数量。</p>

File diff suppressed because one or more lines are too long

Binary file not shown.