Find the smallest element in the unsorted side. Sorted side Unsorted side.[r]
Trang 1Chapter 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
Data Structures
and Other Objects
Trang 2The picture
shows an
array of six
integers that
we want to
sort from
smallest to
largest
0 10 20 30 40 50 60 70
Trang 30 10 20 30 40 50 60 70
The Selectionsort Algorithm
Start by
finding the
smallest
entry
Trang 40 10 20 30 40 50 60 70
The Selectionsort Algorithm
Start by
finding the
smallest
entry
Swap the
smallest
entry with
the first
entry
Trang 50 10 20 30 40 50 60 70
The Selectionsort Algorithm
Start by
finding the
smallest
entry
Swap the
smallest
entry with
the first
entry
Trang 60 10 20 30 40 50 60 70
The Selectionsort Algorithm
Part of the
array is now
sorted
Sorted side Unsorted side
Trang 7Find the
smallest
element in
the unsorted
side
Sorted side Unsorted side
Trang 8Find the
smallest
element in
the unsorted
side
Swap with
the front of
the unsorted
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
Trang 9We have
increased the
size of the
sorted side
by one
element
Sorted side Unsorted side
Trang 10The process
continues
Sorted side Unsorted side
Smallest from unsorted
Smallest from unsorted