"Select Sort"
The selection sort is based on a bubbling sort (Bubble sort) that has been improved: each visit process (pass) needs to be exchanged at most.
Each visit process, to find the maximum value, when the end of the visit, the maximum value is exchanged to the correct position;
Then continue to repeat the process in the remaining sublist until the n-1 visit is completed (n is the length of the list);
At this point, the remaining elements in the list are automatically aligned to the correct position.
A list of length n=9 is given: The first visit finds the maximum value of 93 and swaps it to the far right of the list, that is, Exchange 93 and 20, and the second visit finds the maximum value in the remaining list 77 and says it swaps to the far right of the remaining list, that is, 77 and 55, and so on until the n-1=8 visit is completed, The list sort is complete. For the fifth time in the example, 44 is the maximum value in the remaining list, which happens to be in the correct position, and does not need to be exchanged.
"Implementation of selection sort"
During the visit we can select the minimum value to swap to the leftmost part of the list, or you can select the maximum value to swap to the far right of the list. Here, for example:
"Performance Analysis"
The number of comparisons is the same as the Bubble sort O (N2), but the number of exchanges decreases compared to the bubble sort.
"Python Learning notes-data structures and algorithms" Selection sorting Selection sort