Skip to content

Instantly share code, notes, and snippets.

@SeaOfLee
Created March 24, 2015 16:54
Show Gist options
  • Select an option

  • Save SeaOfLee/2d86eab119b4357928af to your computer and use it in GitHub Desktop.

Select an option

Save SeaOfLee/2d86eab119b4357928af to your computer and use it in GitHub Desktop.
Selection Sort

Selection sort is an in-place comparison sort. It is inefficient on large lists, and generally performs worse than the similar insertion sort.

Selection sort divides the input list into two parts: the sublist of items already sorted (built up from left to right at the front of the list), and the sublist of remaining unsorted items that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.

Works well on small files, inefficient for large lists. Almost always outperformed by the similar insertion sort algorithm. Big O performance is poor compared to other algorithms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment