Selection Sort Presentation
Selection Sort Presentation
Christian De la Torre
Nhiel Carlo Montellano
Jhon Matinong
Selection Sort Algorithm
Selection sort is a simple and efficient sorting algorithm that
works by repeatedly selecting the smallest (or largest) element
from the unsorted portion of the list and moving it to the sorted
portion of the list.
currentIndex = 0
i = 0
min = 20
20 12 10 15 2
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 0
i = 1
min = 12
20 12 10 15 2
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 0
i = 2
min = 10
20 12 10 15 2
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 0
i = 3
min = 10
20 12 10 15 2
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 0
i = 4
min = 2
20 12 10 15 2
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 0
i = 4
min = 20
2 12 10 15 20
Swapping
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 1
2 12 10 15 20
i = 2
min = 12
2 12 10 15 20
i = 3
min = 10
2 12 10 15 20
i = 4
min = 10
i = 4
2 10 12 15 20
min = 12
Swapping
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 2
2 10 12 15 20
i = 2
min = 12
2 10 12 15 20
i = 3
min = 12
2 10 12 15 20
i = 4
min = 12
Already
Sorted
Compare minimum with the third element. Again, if the third element is smaller, then assign minimum to the third element otherwise do nothing. The process goes on until the last element.
currentIndex = 3
2 10 12 15 20
i = 3
min = 15
2 10 12 15 20
i = 4
min = 15
Already
Sorted
procedure selectionSort(array: array of integers)
n := length(array)
for i from 0 to n - 1 do
min := i
for j from i to n - 1 do
if array[min] > array[j] then
min := j
end if
end for
temp := array[i]
array[i] := array[min]
array[min] := temp
end for
end procedure
Time Complexities