mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-18 14:30:58 +00:00
deploy
This commit is contained in:
@@ -4932,7 +4932,7 @@
|
||||
</div>
|
||||
<h2 id="1121-algorithm-characteristics">11.2.1 Algorithm Characteristics<a class="headerlink" href="#1121-algorithm-characteristics" title="Permanent link">¶</a></h2>
|
||||
<ul>
|
||||
<li><strong>Time complexity <span class="arithmatex">\(O(n^2)\)</span>, non-adaptive sorting</strong>: The outer loop has <span class="arithmatex">\(n - 1\)</span> rounds in total. The length of the unsorted interval in the first round is <span class="arithmatex">\(n\)</span>, and the length of the unsorted interval in the last round is <span class="arithmatex">\(2\)</span>. That is, the rounds of the outer loop contain inner loops with <span class="arithmatex">\(n\)</span>, <span class="arithmatex">\(n - 1\)</span>, <span class="arithmatex">\(\dots\)</span>, <span class="arithmatex">\(3\)</span>, and <span class="arithmatex">\(2\)</span> iterations, summing to <span class="arithmatex">\(\frac{(n - 1)(n + 2)}{2}\)</span>.</li>
|
||||
<li><strong>Time complexity <span class="arithmatex">\(O(n^2)\)</span>, non-adaptive sorting</strong>: The outer loop has <span class="arithmatex">\(n - 1\)</span> rounds in total. The inner loop runs <span class="arithmatex">\(n - 1\)</span> times in the first round and <span class="arithmatex">\(1\)</span> time in the last round. Thus, it runs <span class="arithmatex">\(n - 1\)</span>, <span class="arithmatex">\(n - 2\)</span>, <span class="arithmatex">\(\dots\)</span>, <span class="arithmatex">\(2\)</span>, and <span class="arithmatex">\(1\)</span> times across the rounds, summing to <span class="arithmatex">\(\frac{n(n - 1)}{2}\)</span>.</li>
|
||||
<li><strong>Space complexity <span class="arithmatex">\(O(1)\)</span>, in-place sorting</strong>: Pointers <span class="arithmatex">\(i\)</span> and <span class="arithmatex">\(j\)</span> use a constant amount of extra space.</li>
|
||||
<li><strong>Unstable sorting</strong>: As shown in Figure 11-3, element <code>nums[i]</code> may be swapped to the right of an element equal to it, causing a change in their relative order.</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user