Selection Sort

Selection sort is a simple sorting algorithm that works by iterating over the elements and selecting the correct element for each position. Once it is found, it is swapped with the current position.

It simply starts from the left and selects the smallest element and moves it to the correct place. It then moves to the next position and repeats this process until all the elements are in the correct position.

Selection sort is a very slow sort algorithm due to needing n comparisons to select the correct element for each n positions. Thus the time complexity is O(n^2).

The red line represents the position where the next smallest element is to be placed.

Settings