This commit is contained in:
krahets
2023-08-22 13:50:24 +08:00
parent 77b90cd19b
commit b70b7c9e75
67 changed files with 580 additions and 580 deletions

View File

@@ -3426,16 +3426,16 @@
<h1 id="116">11.6 &nbsp; 归并排序<a class="headerlink" href="#116" title="Permanent link">&para;</a></h1>
<p>「归并排序 merge sort」是一种基于分治策略的排序算法包含图所示的“划分”和“合并”阶段:</p>
<p>「归并排序 merge sort」是一种基于分治策略的排序算法包含图 11-10 所示的“划分”和“合并”阶段:</p>
<ol>
<li><strong>划分阶段</strong>:通过递归不断地将数组从中点处分开,将长数组的排序问题转换为短数组的排序问题。</li>
<li><strong>合并阶段</strong>:当子数组长度为 1 时终止划分,开始合并,持续地将左右两个较短的有序数组合并为一个较长的有序数组,直至结束。</li>
</ol>
<p><img alt="归并排序的划分与合并阶段" src="../merge_sort.assets/merge_sort_overview.png" /></p>
<p align="center">归并排序的划分与合并阶段 </p>
<p align="center"> 11-10 &nbsp; 归并排序的划分与合并阶段 </p>
<h2 id="1161">11.6.1 &nbsp; 算法流程<a class="headerlink" href="#1161" title="Permanent link">&para;</a></h2>
<p>图所示,“划分阶段”从顶至底递归地将数组从中点切为两个子数组:</p>
<p>如图 11-11 所示,“划分阶段”从顶至底递归地将数组从中点切为两个子数组:</p>
<ol>
<li>计算数组中点 <code>mid</code> ,递归划分左子数组(区间 <code>[left, mid]</code> )和右子数组(区间 <code>[mid + 1, right]</code> )。</li>
<li>递归执行步骤 <code>1.</code> ,直至子数组区间长度为 1 时,终止递归划分。</li>
@@ -3475,7 +3475,7 @@
</div>
</div>
</div>
<p align="center">归并排序步骤 </p>
<p align="center"> 11-11 &nbsp; 归并排序步骤 </p>
<p>观察发现,归并排序的递归顺序与二叉树的后序遍历相同,对比来看:</p>
<ul>