home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug117.arc
/
SORTS.LBR
/
SORTS.DQC
/
SORTS.DOC
Wrap
Text File
|
1979-12-31
|
3KB
|
57 lines
SORT.CO═áá i≤áá prograφá shel∞á designeΣá t∩áá allo≈ ì
comparisoεá oµá ßá numbe≥á oµá sortinτáá algorithms« ì
SORT.PA╙á i≤á thσ correspondinτ Turb∩ Pasca∞á sourcσ ì
file«á Thσ prograφ men⌡ allow≤ thσ use≥ t∩ generatσ ì
ß desireΣ numbe≥ oµ randoφ integer≤ (u≡ t∩ 2000¼ bu⌠ ì
treσá sor⌠ caε handlσ onl∙ 1600)«á Thσ maste≥á lis⌠ ì
caεá bσá presorteΣ iµ desired¼á anΣ displa∙á oµá thσ ì
number≤á caε bσ toggleΣ oε o≥ off«á Thσ othe≥á men⌡ ì
choice≤á allo≈á thσá use≥á t∩á tes⌠á thσá particula≥ ì
sorting methods.
Thσá individua∞á sortinτ algorithm≤ appea≥ a≤á nameΣ ì
procedure≤á withiε SORT.PAS«á The∙ werσ writteεá t∩ ì
gaiε understandinτ oµ thσ sorts¼á anΣ werσ optimizeΣ ì
fo≥á clea≥á expressioε rathe≥á thaεá versatilit∙á o≥ ì
speed«á
T∩á comparσ thσ speeΣ oµ thσ variou≤á algorithms¼á ╔ ì
timeΣ thσ interva∞ betweeε m∙ responsσ t∩ thσ promp⌠ ì
"Ready?óá anΣ thσ momen⌠ wheε thσ sorteΣ lis⌠á begaε ì
t∩á prin⌠á out«á ╔ testeΣ eacΦ sor⌠ oε 40░ anΣá 80░ ì
randoφá integers¼á anΣ theε oε thσ samσ numbe≥á set≤ ì
afte≥ presorting¼á witΦ thσ followinτ result≤ (time≤ ì
in seconds):
SORT 400 800 400 (PS) 800 (PS)
bubble 29.7 114.8 .3 .3
count 17.8 70.2 18.0 71.0
insert 11.5 42.2 .4 .4
select 9.2 35.6 9.1 35.4
tree 6.3 14.1 6.3 14.0
shell 1.9 4.0 1.1 2.1
heap 1.6 3.5 1.7 3.6
quick1 1.1 2.1 8.7 failed
quick2 1.0 2.0 .7 1.2
Thσ firs⌠ fou≥ sort≤ arσ oµ ß clas≤ tha⌠ take≤á timσ ì
proportiona∞á t∩ ε *¬ ▓ t∩ sor⌠ ε items¼á shel∞ sor⌠ ì
i≤áá iεá aεá intermediatσá clas≤á tha⌠á take≤áá timσ ì
proportiona∞á t∩ roughl∙ ε *¬ 1.25¼á anΣá thσá othe≥ ì
fou≥á arσá iεá thσ bes⌠ casσ clas≤ tha⌠á take≤á timσ ì
proportiona∞ t∩ ε loτ n«á
Notσá tha⌠ tw∩ oµ thσ ver∙ simplσ sort≤ (bubblσá anΣ ì
insertion⌐á arσ excellen⌠ oε list≤ tha⌠ arσá alread∙ ì
sorteΣ o≥ nearl∙ so«á Treσ sor⌠ i≤ worsσ thaε shel∞ ì
sor⌠á a⌠á ε thi≤ lo≈ becausσ oµ higΦá overhead¼á bu⌠ ì
woulΣá eventuall∙ catcΦ u≡ a⌠ mucΦá large≥á n«á Thσ ì
simplσá quicδá sor⌠ i≤ notoriousl∙ baΣ oεá presorteΣ ì
lists--a⌠á εá ╜ 80░ i⌠ fail≤ duσ t∩á stacδá overflo≈ ì
durinτá recursivσ calls«á Thσ improveΣá quicδá sor⌠ ì
overcome≤á thi≤ probleφ anΣ wil∞ bσ thσ fastes⌠ sor⌠ ì
oµá thi≤á collectioεá fo≥á al∞á bu⌠á ver∙áá unlikel∙ ì
sequence≤á oµ numbers«á (Iε ß fe≈ rarσ cases¼á hea≡ ìèsor⌠á wil∞á bea⌠ it¼á sincσ thσá improveΣá quicksor⌠ ì
stil∞á ha≤ ß baΣ wors⌠ case¼á whilσ hea≡ sor⌠á take≤ ì
about the same time for best and worse case lists.)