The selection sort algorithm works by iterating through an array, finding the minimum/maximum value, and swapping it into the correct sorted position. It does this by keeping track of the index of the minimum/maximum value found on each pass. The number of passes is equal to the length of the array. In each pass, it finds the minimum/maximum value and swaps it into the current place, sorting the array further.