mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 15:06:07 +00:00
deploy
This commit is contained in:
@@ -3610,7 +3610,7 @@
|
||||
<!-- Page content -->
|
||||
<h1 id="113-bubble-sort">11.3 Bubble sort<a class="headerlink" href="#113-bubble-sort" title="Permanent link">¶</a></h1>
|
||||
<p><u>Bubble sort</u> achieves sorting by continuously comparing and swapping adjacent elements. This process resembles bubbles rising from the bottom to the top, hence the name bubble sort.</p>
|
||||
<p>As shown in the following figures, the bubbling process can be simulated using element swap operations: starting from the leftmost end of the array and moving right, sequentially compare the size of adjacent elements. If "left element > right element," then swap them. After the traversal, the largest element will be moved to the far right end of the array.</p>
|
||||
<p>As shown in Figure 11-4, the bubbling process can be simulated using element swap operations: starting from the leftmost end of the array and moving right, sequentially compare the size of adjacent elements. If "left element > right element," then swap them. After the traversal, the largest element will be moved to the far right end of the array.</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="1:7"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1"><1></label><label for="__tabbed_1_2"><2></label><label for="__tabbed_1_3"><3></label><label for="__tabbed_1_4"><4></label><label for="__tabbed_1_5"><5></label><label for="__tabbed_1_6"><6></label><label for="__tabbed_1_7"><7></label></div>
|
||||
<div class="tabbed-content">
|
||||
<div class="tabbed-block">
|
||||
@@ -3639,7 +3639,7 @@
|
||||
<p align="center"> Figure 11-4 Simulating bubble process using element swap </p>
|
||||
|
||||
<h2 id="1131-algorithm-process">11.3.1 Algorithm process<a class="headerlink" href="#1131-algorithm-process" title="Permanent link">¶</a></h2>
|
||||
<p>Assuming the length of the array is <span class="arithmatex">\(n\)</span>, the steps of bubble sort are shown below.</p>
|
||||
<p>Assuming the length of the array is <span class="arithmatex">\(n\)</span>, the steps of bubble sort are shown in Figure 11-5.</p>
|
||||
<ol>
|
||||
<li>First, perform a "bubble" on <span class="arithmatex">\(n\)</span> elements, <strong>swapping the largest element to its correct position</strong>.</li>
|
||||
<li>Next, perform a "bubble" on the remaining <span class="arithmatex">\(n - 1\)</span> elements, <strong>swapping the second largest element to its correct position</strong>.</li>
|
||||
|
||||
Reference in New Issue
Block a user