Skip to main content

Selection Sort

Learn Selection Sort (Sorting, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Selection Sort - O(n²) Repeatedly finds the MINIMUM element in the unsorted portion and swaps it into its correct position at the front. Simple, but always O(n²) comparisons regardless of input order - even an already-sorted array gets the full treatment. In-place - O(1) extra space. Not stable - a swap can jump a value past an equal one, changing relative order. Fewest swaps of the common O(n²) sorts - at most n-1 swaps total, which matters when swaps are expensive (e.g. large objects).

More lessons in Sorting