Selection Sort

Selection sort repeatedly selects the smallest element from the unsorted portion and places it at the beginning.

Selection Sort Visualization

Complexity

Time Complexity: O(n^2)
Space Complexity: O(1)

Pseudocode

for i from 0 to n-1:
  minIndex = i
  for j from i+1 to n:
    if arr[j] < arr[minIndex]:
      minIndex = j
  swap(arr[i], arr[minIndex])