function selectionSort(arr):
n = arr.length
for i from 0 to n-2:
minIdx = i
for j from i+1 to n-1:
if arr[j] < arr[minIdx]:
minIdx = j
swap(arr[i], arr[minIdx])
Time: always. The inner loop runs times regardless of input.
Space: . Only a few variables for indices(except for the memory array itself).
Stability: Stable. Equal elements maintain their relative order.
Selection sort is simple but slow. Use it only for tiny arrays or when swaps are expensive (since it does exactly swaps).