Selection sort
This method is called selection sort because it works by repeatedly selecting the smallest remaining item。
Selection sort uses ~N2/2 compares and N exchanges to sort an array of length N.
- First, find the smallest item in the array, and exchange it with the first entry。
- Then, find the next smallest item and exchange it with the second entry。
- Continue in this way until the entire array is sorted。
source code: Selection.java
结论:
- 算法运行时间和输入无关。这意味着即使输入的数组有序,也要进行一趟扫描。
- 数据的移动最少。交换次数和数组大小是线性关系。
insert sort
sorting algorithm
时间: 2024-08-24 15:38:54