版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、计算机算法导论_第8章课件计算机算法导论_第8章课件Sorting and Order StatisticsIntroductionSorting and Order StatisticsInSorting problemDefinition:Input: A sequence of numbers.Output: A permutation , such that a1 a2 an .Sorting problemDefinition:The structure of the dataDefinition:Record = key + satellite dataAssumption:The
2、 input consists only of numbersThe structure of the dataDefinWhy sorting?The need inherent in an applicationAlgorithms often use sorting as a key subroutineA wide variety of sorting algorithms, a rich set of techniquesA problem can be proved a nontrivial lower bound.Many engineering issues come to f
3、ore when implementing sorting algorithms. Why sorting?The need inherent Sorting algorithmsA in-place sorting algorithmComparison sortThe counting sort algorithmThe radix sort algorithmThe bucket sort algorithmSorting algorithmsA in-place sOrder statisticsThe ith order statistic of a set of n numbers
4、 is the ith smallest number in the set.Order statisticsThe ith order 8、 Sorting in linear time8、 Sorting in linear time8.1 Lower bounds for sortingAssumption:All of the input elements are distinctAll comparisons have the form ai aj 8.1 Lower bounds for sortingAsHow fast can we sort?All the sorting a
5、lgorithms we have seen so far are comparison sorts: only use comparisons to determine the relative order of elements.E.g.,insertion sort, merge sort, quicksort, heapsort.The best worst-case running time that weve seen for comparison sorting is O(n lg n) .Is O(n lg n) the best we can do?Decision tree
6、s can help us answer this question.How fast can we sort?All the s计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件Decision-tree modelA decision tree can model the execution of any comparison sort: One tree for each input size n. View the algorithm as splitting whenever it compares tw
7、o elements. The tree contains the comparisons along all possible instruction traces. The running time of the algorithm = the length of the path taken. Worst-case running time = height of tree.Decision-tree modelA decision Lower bound for decision-tree sortingLower bound for decision-tree Lower bound
8、 for comparison sortingCorollary. Heapsort and merge sort are asymptotically optimal comparison sorting algorithms.Lower bound for comparison sor8.2 Counting sortSorting in linear timeCounting sort: No comparisons between elements. Input: A1 . . n, where A j1, 2, , k . Output: B1 . . n, sorted. Auxi
9、liary storage: C1 . . k .8.2 Counting sortSorting in liCounting sortfor i 1 to k do Ci 0for j 1 to n do CA j CA j + 1 Ci = |key = i|for i 2 to k do Ci Ci + Ci1 Ci = |key i|for j n downto 1 do BCA j A j CA j CA j 1Counting sortfor i 1 to k计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8
10、章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件Running timeIf k = O(n), then counting sort takes (n) time. But, sorting takes (n lg n) time! Wheres the fallacy?Answer: Comparison sorting takes (n lg n)
11、 time. Counting sort is not a comparison sort. In fact, not a single comparison between elements occurs!Running timeIf k = O(n), then 计算机算法导论_第8章课件8.3 Radix sort Origin: Herman Holleriths card-sorting machine for the 1890 U.S. Census. (See Appendix .) Digit-by-digit sort. Holleriths original (bad) i
12、dea: sort on most-significant digit first. Good idea: Sort on least-significant digit first with auxiliary stable sort.8.3 Radix sort Origin: Herma计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件计算机算法导论_第8章课件8.4 Bucket sortAssumption:The input is drawn from a uniform distr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 自动化生产线设备维护技术规范
- 临床泛水应急预案(3篇)
- 别墅外沿施工方案(3篇)
- 工地疫情施工方案(3篇)
- 井巷施工方案范本(3篇)
- 报警按钮施工方案(3篇)
- 天花改造施工方案(3篇)
- 喷顶施工方案(3篇)
- 施工方案模板范(3篇)
- 抗原检测应急预案(3篇)
- 北京通州产业服务有限公司招聘笔试备考题库及答案解析
- 2026届江苏省扬州市江都区大桥、丁沟、仙城中学生物高一上期末联考模拟试题含解析
- 2025-2026学年辽宁省沈阳市和平区七年级(上)期末语文试卷(含答案)
- 2026广东广州开发区统计局(广州市黄埔区统计局)招聘市商业调查队队员1人参考题库完美版
- 君山岛年度营销规划
- 10月住院医师规范化培训《泌尿外科》测试题(含参考答案解析)
- 初中英语写作教学中生成式AI的应用与教学效果评估教学研究课题报告
- 期末测试卷(试卷)2025-2026学年三年级数学上册(人教版)
- 2025年福建江夏学院毛泽东思想和中国特色社会主义理论体系概论期末考试模拟题及答案1套
- DB32T 5132.3-2025 重点人群职业健康保护行动指南 第3部分:医疗卫生人员
- GJB3206B-2022技术状态管理
评论
0/150
提交评论