我们的老师没有教我们如何分析算法的运行时间,然后她想让我们报告一下Shell sort。
我只想知道是否有一种简单的方法可以找到像 shell 排序这样的算法的平均/最佳/最差情况性能。
//for references
class ShellSort{
void shellSort(int array[], int n){
//n = array.length
for (int gap = n/2; gap > 0; gap /= 2){
for (int i = gap; i < n; i += 1) {
int temp = array[i];
int j;
for (j = i; j >= gap && array[j - gap] > temp; j -= gap){
array[j] = array[j - gap];
}
array[j] = temp;
}
}
}