面向研究生入学考试编程:排序算法 05 七个泛化排序算法的时间比较 木灵的炼金工作室

使用随机数发生器发生一个$[0, 20000]$的数组,用七种基础排序算法(选择,插入,冒泡,希尔,堆,归并,快速)排序并记录时间。使用不同的数组长度来比较时间增长率:

数据

200 numbers: 

selection sort:0.003988027572631836
insert sort:0.004050254821777344
bubble sort:0.007954835891723633
shell sort:0.0009968280792236328
heap sort:0.0
merge sort:0.001992940902709961
quick sort:0.0030019283294677734


400 numbers: 

selection sort:0.01600503921508789
insert sort:0.023973703384399414
bubble sort:0.020000934600830078
shell sort:0.0020411014556884766
heap sort:0.0009748935699462891
merge sort:0.006982564926147461
quick sort:0.0059986114501953125


800 numbers: 

selection sort:0.05400204658508301
insert sort:0.09109711647033691
bubble sort:0.10801887512207031
shell sort:0.005997657775878906
heap sort:0.0019986629486083984
merge sort:0.02700328826904297
quick sort:0.010001420974731445


1600 numbers: 

selection sort:0.23199701309204102
insert sort:0.36003565788269043
bubble sort:0.3070957660675049
shell sort:0.008002758026123047
heap sort:0.002047300338745117
merge sort:0.030986785888671875
quick sort:0.018038272857666016


3200 numbers: 

selection sort:0.7659487724304199
insert sort:1.2110509872436523
bubble sort:1.145033836364746
shell sort:0.014962434768676758
heap sort:0.0030357837677001953
merge sort:0.057001590728759766
quick sort:0.026999711990356445


6400 numbers: 

selection sort:2.8795769214630127
insert sort:5.089568376541138
bubble sort:4.660359859466553
shell sort:0.03900456428527832
heap sort:0.005001544952392578
merge sort:0.13099980354309082
quick sort:0.06100130081176758


12800 numbers: 

selection sort:13.064777612686157
insert sort:21.136166095733643
bubble sort:20.286521434783936
shell sort:0.08303189277648926
heap sort:0.013004779815673828
merge sort:0.25247859954833984
quick sort:0.14045262336730957


25600 numbers: 

selection sort:47.64990949630737
insert sort:73.97752547264099
bubble sort:70.65206933021545
shell sort:0.14007258415222168
heap sort:0.02303481101989746
merge sort:0.4960310459136963
quick sort:0.27300024032592773


51200 numbers: 

shell sort:1.0519988536834717
heap sort:0.04699873924255371
merge sort:1.0518486499786377
quick sort:0.5499985218048096


102400 numbers: 

shell sort:2.1720407009124756
heap sort:0.09005141258239746
merge sort:2.261751174926758
quick sort:1.2129664421081543


204800 numbers:

shell sort:4.961047172546387
heap sort:0.20299696922302246
merge sort:4.463998556137085
quick sort:2.552473545074463


409600 numbers:

shell sort:12.320789337158203
heap sort:0.4305448532104492
merge sort:9.757027864456177
quick sort:5.634234428405762

作个图:
排序

对比还是很强烈的


Copyright AmachiInori 2017-2021. All Right Reserved.
Powered By Jekyll.
amachi.com.cn