mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-08 13:36:06 +00:00
deploy
This commit is contained in:
@@ -3895,8 +3895,8 @@
|
||||
<p align="center"> 图 12-8 构建二叉树的递归过程 </p>
|
||||
|
||||
<p>每个递归函数内的前序遍历 <code>preorder</code> 和中序遍历 <code>inorder</code> 的划分结果如图 12-9 所示。</p>
|
||||
<p><img alt="built_tree_overall" src="../build_binary_tree_problem.assets/built_tree_overall.png" /></p>
|
||||
<p align="center"> 图 12-9 built_tree_overall </p>
|
||||
<p><img alt="每个递归函数中的划分结果" src="../build_binary_tree_problem.assets/built_tree_overall.png" /></p>
|
||||
<p align="center"> 图 12-9 每个递归函数中的划分结果 </p>
|
||||
|
||||
<p>设树的节点数量为 <span class="arithmatex">\(n\)</span> ,初始化每一个节点(执行一个递归函数 <code>dfs()</code> )使用 <span class="arithmatex">\(O(1)\)</span> 时间。<strong>因此总体时间复杂度为 <span class="arithmatex">\(O(n)\)</span></strong> 。</p>
|
||||
<p>哈希表存储 <code>inorder</code> 元素到索引的映射,空间复杂度为 <span class="arithmatex">\(O(n)\)</span> 。最差情况下,即二叉树退化为链表时,递归深度达到 <span class="arithmatex">\(n\)</span> ,使用 <span class="arithmatex">\(O(n)\)</span> 的栈帧空间。<strong>因此总体空间复杂度为 <span class="arithmatex">\(O(n)\)</span></strong> 。</p>
|
||||
|
||||
Reference in New Issue
Block a user