Selectionsort is a simple and intuitive sorting algorithm. It works as follows. First, find the minimum element in the unordered sequence and store it to the starting position of the sorting sequence. Then, find the minimum element from the remaining unordered elements and put it at the end of the sorting sequence. And so on until all elements are sorted. The switch operation for sorting is between 0 and (n? 1. Select n (n? 1)/2
Selection sort is a simple and intuitive sorting algorithm. It works as follows. First, find the minimum element in the unordered sequence and store it to the starting position of the sorting sequence. Then, find the minimum element from the remaining unordered elements and put it at the end of the sorting sequence. And so on until all elements are sorted.
The switch operation for sorting is between 0 and (n? 1. Select n (n? 1. The value assignment operation for sorting is between 0 and 3 (n? 1.
Number of comparisons O (n ^ 2), the number of comparisons has nothing to do with the initial state of the keyword, the total number of comparisons N = (n-1) + (n-2) +... + 1 = n * (n-1)/2. The number of exchanges O (n). The best case is that it has been ordered and has been exchanged for 0 times. The worst case is reverse order, where it has been exchanged for N-1 times. The number of swapping times is much less than that of bubble sorting. because the CPU time required for switching is much longer than the CPU time required by the comparison, and the n value is small, the selection sorting is faster than bubble sorting.