Selection Sort





Definition: A process designed to sort an unordered set of linear data into either ascending order (lowest to highest) or descending order (highest to lowest). This is done by comparing the first item in the list to all of the items to the right of it. Assuming that we are sorting the list in ascending order, the lowest element in the list and the first element are swapped (if the first element is the lowest element, it remains in place). This same process is now repeated with the second element in the list and all those to the right of it. Then, it is repeated with the third element, fourth, and so on until the second to last element. See an example of the procedure below.


Procedure for ASCENDING Selection Sort:

  1. Check every element in the list one by one to find the minimum element.
  2. Once the minimum element has been located, swap it with the first element. If the minimum element is the first element, make no changes.
  3. Repeat step 1 but starting from the second element instead of the first. The first element can be disregarded because it has already been sorted.
  4. Locate the minimum element. Here, the minimum element happens to be the second element so no swaps are made.
  5. Repeat steps 1 and 2 for every element through the second to last. Below is the process for the third element.
  6. After a few more repititions of steps 1 and 2, the list is finally sorted.

Fun Fact: Selection sort is one of the simplest sorting algorithms available but also one of the slowest. For a dataset containing 10,000 elements, a quick sort sorts the data over 700 times faster than a selection sort.



Commonly Used In: