The Selection Sort Algorithm

The selection sort algorithm has the worst case running time of O(n2) complexity. Given an array it scans from left to right to find the smallest number in the array. Once the algorithm is done scanning the entire array and the smallest number has been found, it is swapped into the first space. Then the scanning process starts over again, but this time from the second space. Once a new minimum has been found, that will be swapped into the second space. And so on.
This is a pseudo code:

Procedure: selectionSort(a)
Inputs:
- a: the array to sort
Output:
- a: the array in sorted ascending order
Process:
1) For i = 0 to a.length:
a) Set minimum to i
b) For j = i + 1 to a.length. If a[j] < a[minimum], then set minimum to j
c) Swap a[i] with a[minimum]
2) Return the sorted array

Code in Java

public static int[] selectionSort(int a[]) {
for (int i = 0; i < a.length; i++) {
int minimum = i;
for (int j = i + 1; j < a.length; j++) {
if (a[j] < a[minimum]) minimum = j;
}
int temp = a[i];
a[i] = a[minimum];
a[minimum] = temp;
}
return a;
}