【发布时间】:2026-01-19 06:45:01
【问题描述】:
我们的老师没有教我们如何分析算法的运行时间,然后她想让我们报告一下 Shell 排序。
我只是想知道是否有一种简单的方法可以找到 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;
}
}
}
【问题讨论】:
标签: java performance time-complexity shellsort