Selection Sort follows very simple idea.

Let us see  what is the idea of Selection Sort :

  • First it finds the smallest element in the array.
  • Exchange that smallest element with the element at the first position.
  • Then find the second smallest element and exchange that element with the element at the second position.
  • This process continues until the complete array is sorted.

Let us see how selection sort works :

Pseudocode of Selection Sort

SELECTION-SORT(A)
1.     for j ← 1 to n-1
2.          smallest ← j
3.           for i ← j + 1 to n
4.                   if A[ i ] < A[ smallest ]
5.                          smallest ← i
6.            Exchange A[ j ] ↔ A[ smallest ]

Disadvantage of selection sort is : Running time of selection sort depends only slightly on the amount of order in the file.