希尔排序
来源:互联网 发布:最新的数据库处理技术 编辑:程序博客网 时间:2024/06/07 04:09
# coding=utf-8from imooc.dataStructure.two.RandomTestcase import *'''shell排序是插入排序的优化,时间复杂度最差是O(n^2),最好和插入排序一样是O(n),平均是O(n^3/2)'''''' 测试算法的性能 '''def testSort(sortName, sortfunc, arr, n): start = time.time() sortfunc(arr, n) end = time.time() # assert (isSorted(arr, n)) print("%s:%f" % (sortName, end-start)) returndef shellSort(arr,n): step = 0 while step <= n/3: '''选取3n+1的步长''' step = step*3+1 while step > 0: for i in range(step,n): key = arr[i] j=i while j > 0 and arr[j-step] > key: arr[j] = arr[j-step] j-=step arr[j] = key step = (step-1)//3arr = generateRandomArray(10000,0,10000)testSort('shellsort',shellSort,arr,len(arr))# shellSort(arr,len(arr))# print(arr)
阅读全文
0 0
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- Tcp三次握手,四次挥手
- RankNet,LambdaRank,LambdaMart
- 解析各大电子商务网站订单号的生成方式
- 评价指标——P,AP,MAP
- eclipse 使用extjs做发开,总是卡死
- 希尔排序
- Sqoop安装配置教程
- mac scala搭建
- 前端之git常用命令
- Alamofire源码分析
- 单独刷新页面中ckfinder部分,ckfinder如何重新加载
- GMM
- android studio signature version
- 数字签名机制