




已阅读5页,还剩52页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Introduction to Algorithms 计算机算法导论,20072008年第一学期,Sorting and Order Statistics,Introduction,Sorting problem,Definition: Input: A sequence of numbers. Output: A permutation , such that a1 a2 an .,The structure of the data,Definition: Record = key + satellite data Assumption: The input consists only of numbers,Why sorting?,The need inherent in an application Algorithms often use sorting as a key subroutine A wide variety of sorting algorithms, a rich set of techniques A problem can be proved a nontrivial lower bound. Many engineering issues come to fore when implementing sorting algorithms.,Sorting algorithms,A in-place sorting algorithm Comparison sort The counting sort algorithm The radix sort algorithm The bucket sort algorithm,Order statistics,The ith order statistic of a set of n numbers is the ith smallest number in the set.,8、 Sorting in linear time,8.1 Lower bounds for sorting,Assumption: All of the input elements are distinct All comparisons have the form ai aj,How fast can we sort?,All the sorting algorithms 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 trees can help us answer this question.,Decision-tree model,A 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 two 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.,Lower bound for decision-tree sorting,Lower bound for comparison sorting,Corollary. Heapsort and merge sort are asymptotically optimal comparison sorting algorithms.,8.2 Counting sort,Sorting in linear time Counting sort: No comparisons between elements. Input: A1 . . n, where A j1, 2, , k . Output: B1 . . n, sorted. Auxiliary storage: C1 . . k .,Counting sort,for i 1 to k do Ci 0 for 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 1,Running time,If 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) time. Counting sort is not a comparison sort. In fact, not a single comparison between elements occurs!,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) idea: sort on most-significant digit first. Good idea: Sort on least-significant digit first with auxiliary stable sort.,8.4 Bucket so
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 无锡学院《英语国家社会与文化一》2023-2024学年第二学期期末试卷
- 唐山海运职业学院《随机过程及其应用》2023-2024学年第二学期期末试卷
- 天津铁道职业技术学院《药理学》2023-2024学年第二学期期末试卷
- 山东省武城县联考2025届初三第二学期5月练习语文试题试卷含解析
- 上海市松江区第七中学2025年初三(下)第一次中考模拟英语试题含答案
- 山东英才学院《建筑识图与制图》2023-2024学年第二学期期末试卷
- 宁夏艺术职业学院《医学影像设备安装与维修学实验》2023-2024学年第二学期期末试卷
- 内江职业技术学院《生物医用材料》2023-2024学年第一学期期末试卷
- 西安市东仪中学2025年高三八校联考数学试题(四)含解析
- 宿州职业技术学院《音乐剧目排练与创编》2023-2024学年第二学期期末试卷
- 和面机设计说明书毕业设计
- JJG 8-1991水准标尺
- GB/T 4857.17-2017包装运输包装件基本试验第17部分:编制性能试验大纲的通用规则
- 直流汇流箱知识培训
- 综合工业废水处理PACT工艺
- GA/T 16.31-2017道路交通管理信息代码第31部分:交通违法行为类别代码
- 焊工(中级工)技能鉴定考核评分表
- 恶性黑色素瘤护理查房课件
- 鸿门宴-课本剧-课件
- 我是家里的小帮手课件
- 2023年江苏安东控股集团有限公司招聘笔试题库及答案解析
评论
0/150
提交评论