计算机算法导论_第8章课件

PPT
  • 阅读 86 次
  • 下载 0 次
  • 页数 58 页
  • 大小 1.891 MB
  • 2022-12-01 上传
  • 收藏
  • 违规举报
  • © 版权认领
下载文档30.00 元 加入VIP免费下载
此文档由【小橙橙】提供上传,收益归文档提供者,本网站只提供存储服务。若此文档侵犯了您的版权,欢迎进行违规举报版权认领
计算机算法导论_第8章课件
可在后台配置第一页与第二页中间广告代码
计算机算法导论_第8章课件
可在后台配置第二页与第三页中间广告代码
计算机算法导论_第8章课件
可在后台配置第三页与第四页中间广告代码
计算机算法导论_第8章课件
计算机算法导论_第8章课件
还剩10页未读,继续阅读
【这是免费文档,您可以免费阅读】
/ 58
  • 收藏
  • 违规举报
  • © 版权认领
下载文档30.00 元 加入VIP免费下载
文本内容

【文档说明】计算机算法导论_第8章课件.ppt,共(58)页,1.891 MB,由小橙橙上传

转载请保留链接:https://www.ichengzhen.cn/view-77476.html

以下为本文档部分文字说明:

计算机算法导论_第8章课件SortingandOrderStatistics•IntroductionSortingproblemDefinition:Input:Asequence<a1,a2,…,an>ofnumbers.Output:Apermuta

tion<a'1,a'2,…,a'n>,suchthata'1≤a'2≤…≤a'n.ThestructureofthedataDefinition:Record=key+satellitedataAssumption:

TheinputconsistsonlyofnumbersWhysorting?1.Theneedinherentinanapplication2.Algorithmsoftenusesortingasakeysubroutine3.Awidevarietyofsorti

ngalgorithms,arichsetoftechniques4.Aproblemcanbeprovedanontriviallowerbound.5.Manyengineeringissuescometoforewhenimplementingsortingalgori

thms.Sortingalgorithms1.Ain-placesortingalgorithm2.Comparisonsort3.Thecountingsortalgorithm4.Theradixsortalgorithm5.Thebucke

tsortalgorithmOrderstatisticsTheithorderstatisticofasetofnnumbersistheithsmallestnumberintheset.8、Sortinginlineartime8.1LowerboundsforsortingAs

sumption:1.Alloftheinputelementsaredistinct2.Allcomparisonshavetheformai≤ajHowfastcanwesort?Allthesortingal

gorithmswehaveseensofararecomparisonsorts:onlyusecomparisonstodeterminetherelativeorderofelements.•E.g.,insertionsort,mergesort,quicksort,heaps

ort.Thebestworst-caserunningtimethatwe’veseenforcomparisonsortingisO(nlgn).IsO(nlgn)thebestwecando?Decisiontreescanhelpusansw

erthisquestion.••••••••••Decision-treemodelAdecisiontreecanmodeltheexecutionofanycomparisonsort:•Onetree

foreachinputsizen.•Viewthealgorithmassplittingwheneveritcomparestwoelements.•Thetreecontainsthecomparisonsalongallpossibleinstructiontraces.

•Therunningtimeofthealgorithm=thelengthofthepathtaken.•Worst-caserunningtime=heightoftree.Lowerboundfordecisi

on-treesortingLowerboundforcomparisonsortingCorollary.Heapsortandmergesortareasymptoticallyoptimalcomparisonsortingalgorithms.8.

2CountingsortSortinginlineartimeCountingsort:Nocomparisonsbetweenelements.•Input:A[1..n],whereA[j]∈{1,2,…,k}.•Output:B[1..n],sorted.•

Auxiliarystorage:C[1..k].Countingsortfori←1tokdoC[i]←0forj←1tondoC[A[j]]←C[A[j]]+1⊳C[i]=|{key=i}|fori←2tokdoC[i]←C[i]+C[i–1]⊳C[i

]=|{key≤i}|forj←ndownto1doB[C[A[j]]]←A[j]C[A[j]]←C[A[j]]–1••••••••••••••••••••••••••••••••RunningtimeIfk=O(n),thencountingsorttakesΘ(n)time.•But

,sortingtakesΩ(nlgn)time!•Where’sthefallacy?Answer:•ComparisonsortingtakesΩ(nlgn)time.•Countingsortisn

otacomparisonsort.•Infact,notasinglecomparisonbetweenelementsoccurs!••8.3Radixsort•Origin:HermanHollerith’scard-sor

tingmachineforthe1890U.S.Census.(SeeAppendix.)•Digit-by-digitsort.•Hollerith’soriginal(bad)idea:sortonmost-significantdi

gitfirst.•Goodidea:Sortonleast-significantdigitfirstwithauxiliarystablesort.••••••••••••••••8.4BucketsortAssump

tion:Theinputisdrawnfromauniformdistribution.IdeaAlgorithmCorrectnessAnalysisAnalysisAnalysisAnalysisAnaly

sisConclusion

小橙橙
小橙橙
文档分享,欢迎浏览!
  • 文档 5420
  • 被下载 8
  • 被收藏 0
相关资源
广告代码123
若发现您的权益受到侵害,请立即联系客服,我们会尽快为您处理。侵权客服QQ:395972555 (支持时间:9:00-21:00) 公众号
Powered by 太赞文库
×
确认删除?