Tải bản đầy đủ (.pdf) (10 trang)

Lecture Data structures and other objects using C++ - Chapter 13: Quadratic sorting - Trường Đại học Công nghiệp Thực phẩm Tp. Hồ Chí Minh

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.66 MB, 10 trang )

<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>

Chapter 13 presents several 
common algorithms for 


sorting an array of integers.
Two slow but simple 


algorithms are 


Selectionsort and 


Insertionsort.


This presentation 


demonstrates how the two 


Quadratic Sorting



<b>Data Structures</b>


</div>
<span class='text_page_counter'>(2)</span><div class='page_container' data-page=2>

Sorting an Array of Integers



The picture 
shows an 
array of six 
integers that 
we want to 
sort from 
smallest to 


largest <b><sub>10</sub>20</b>



</div>
<span class='text_page_counter'>(3)</span><div class='page_container' data-page=3>

<b>10</b>
<b>20</b>
<b>30</b>
<b>40</b>
<b>50</b>
<b>60</b>
<b>70</b>


The Selectionsort Algorithm



Start by 


finding the 


</div>
<span class='text_page_counter'>(4)</span><div class='page_container' data-page=4>

<b>10</b>
<b>20</b>
<b>30</b>
<b>40</b>
<b>50</b>
<b>60</b>
<b>70</b>


The Selectionsort Algorithm



Start by 


finding the 


smallest 


entry.


</div>
<span class='text_page_counter'>(5)</span><div class='page_container' data-page=5>

<b>10</b>
<b>20</b>
<b>30</b>
<b>40</b>
<b>50</b>
<b>60</b>
<b>70</b>


The Selectionsort Algorithm



Start by 


finding the 


smallest 
entry.


</div>
<span class='text_page_counter'>(6)</span><div class='page_container' data-page=6>

<b>10</b>
<b>20</b>
<b>30</b>
<b>40</b>
<b>50</b>
<b>60</b>
<b>70</b>


The Selectionsort Algorithm



Part of the 


array is now 
sorted.


</div>
<span class='text_page_counter'>(7)</span><div class='page_container' data-page=7>

The Selectionsort Algorithm



Find the 
smallest 
element in 
the unsorted 
side.


</div>
<span class='text_page_counter'>(8)</span><div class='page_container' data-page=8>

The Selectionsort Algorithm



Find the 
smallest 
element in 
the unsorted 
side.


Swap with 
the front of 
the unsorted 


</div>
<span class='text_page_counter'>(9)</span><div class='page_container' data-page=9>

The Selectionsort Algorithm



We have 


increased the 
size of the 
sorted side 


by one 


element.


</div>
<span class='text_page_counter'>(10)</span><div class='page_container' data-page=10>

The Selectionsort Algorithm



The process 
continues...


Sorted side Unsorted side


<b>Smallest</b>
<b>from</b>
<b>unsorted</b>


</div>

<!--links-->

×