环境:python3.6、Anaconda 5.1、Jupyter notebook、numba。我用Python生成的随机数组来衡量shell sort的时间复杂度,但是发现它的时间复杂度更符合NlogN。我知道shell排序的时间复杂度是O(n^2),我很困惑。外壳排序代码:def shell_sort(list): n = len(list) gap = n // 2 while gap > 0: for i in range(gap, n): temp = list[i] j = i while j >= gap and list[j - gap] > temp: list[j] = list[j - gap] j -= gap list[j] = temp gap = gap // 2 return list
添加回答
举报
0/150
提交
取消