This page will briefly introduce selection sort.
Definition
Selection sort (English: Selection sort) is a simple and intuitive sorting algorithm. Its working principle is to find the -th smallest element each time (that is, the smallest element in ), and then swap this element with the element at position in the array.
Properties
Stability
The stability of selection sort depends on its specific implementation.
If implemented using a linked list, since insertion and deletion at any position in a linked list are both , there is no need to use a swap (swapping two elements) operation: each time, after selecting the minimum element from the unsorted part (if there are multiple, select the first one), insert it before the first element of the unsorted part, thereby ensuring stability.
If implemented using an array (the usual implementation in OI), since insertion and deletion at any position in an array are both , the only option is to use swap to move elements from the unsorted part to the sorted part. The swap operation makes array-based selection sort unstable.
All implementations given below are based on swapping array elements, and are therefore unstable.
Time complexity
The best-case, average-case, and worst-case time complexities of selection sort are all .