第18讲归并与基数排序ppt课件.ppt

第18讲归并与基数排序ppt课件.ppt

ID:58713018

大小:672.50 KB

页数:42页

时间:2020-10-04

第18讲归并与基数排序ppt课件.ppt_第1页
第18讲归并与基数排序ppt课件.ppt_第2页
第18讲归并与基数排序ppt课件.ppt_第3页
第18讲归并与基数排序ppt课件.ppt_第4页
第18讲归并与基数排序ppt课件.ppt_第5页
资源描述:

《第18讲归并与基数排序ppt课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、排序归并排序与基数排序归并排序 TheMergeAlgorithmThemergealgorithmtakesasequenceofelementsinavectorvhavingindexrange[first,last).Thesequenceconsistsoftwoorderedsublistsseparatedbyanintermediateindex,calledmid.TheMergeAlgorithm…(Cont…)TheMergeAlgorithm…(Cont…)Mergesort归并排序[49][38][65][97]

2、[76][13][27][3849][6597][1376][27][38496597][132776][13273849657697]归并排序的非递归算法mergesort(intsr[],intn){inti,s=1;inttr[20];while(s

3、;while(i+2*s-1

4、等长的两组数据合并*/merge(sr,tr,i,i+s-1,n-1);elsewhile(i

5、t–recursivedefinition(自学)Definition:Asortalgorithmthatsplitstheitemstobesortedintotwogroups,recursivelysortseachgroup,andmergesthemintoafinal,sortedsequence.RuntimeisO(nlogn).MergeSort–Divide-and-ConquerDivide-and-conquerisageneralalgorithmdesignparadigm:Divide:dividethei

6、nputdataSintwodisjointsubsetsS1andS2Recur:solvethesub-problemsassociatedwithS1andS2Conquer:combinethesolutionsforS1andS2intoasolutionforSThebasecasefortherecursionaresub-problemsofsize0or1归并排序的递归算法msort(intx[],intaux[],ints,intt)/*将x[s..t]归并排序为aux[s..t]*/{if(s==t)aux[s]=x

7、[s];else{m=(s+t)/2;msort(x,aux,s,m);msort(x,aux,m+1,t);merge(aux,x,s,m,t);}}MergeSort-example7294

8、3861PartitionMergeSort-example7294

9、386172

10、94Recursivecall,partitionMergeSort-example7294

11、386172

12、947

13、2Recursivecall,partitionMergeSort-example7294

14、386172

15、947

16、277Recursivecall

17、,basecaseMergeSort-example7294

18、386172

19、947

20、27722Recursivecall,basecaseMergeSort-example7294

21、386

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。