尽量少用数学,可以进行估算。适合处理比较大的规模。
使用插值查找将大规模转变为中小规模的序列,然后在使用排序查找算法或二分查找算法对中小规模的序列进行查找。
最坏的时间复杂度 : O(n);
最好的时间复杂度: O(1);
平均的时间复杂度: O(loglogn);
bubble
Try the following algorithm to sort V={19, 17, 23}: 试用以下算法对V={19, 17, 23}排序:
1. Sort by units at first 1. 先按个位排序
2. On the basis of the previous step, sort again by tens 2. 在上一步基础上,再按十位排序
Is this algorithm correct? 这个算法的是否正确?
A
Certainly correct 一定正确
B
Certainly incorrect 一定不正确
C
If the sorting algorithm used in step 2 is stable, then correct 若第2步用的排序算法是稳定的,则正确
D
If the sorting algorithm used in step 1 is stable, then correct 若第1步用的排序算法是稳定的,则正确
If step 2 is not stable, the possible situation is: {19, 17, 23} -> {23, 17, 19} -> {19, 17, 23}
The above algorithm is called “radix sort” and is applicable to the case where the sorted element can be divided into several domains. Its correctness depends on the stability when sorting each domain separately.若第2步不稳定,可能的情况是:{19, 17, 23} -> {23, 17, 19} -> {19, 17, 23}
以上算法称为“基数排序(radix sort)“,适用于被排序元素可分为若干个域的情况,它的正确性要依赖于对每个域分别排序时的稳定性
基数排序(radix sorting);通过将待排序数组元素分配到有限个有序的桶中,然后分别在每个桶内排序,最后按顺序从桶中取出数据放回数组完成排序。