- 1、本文档共73页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
硕士算法2010_第4章_排序算法001讲述
算法设计与分析 李洪伟 博士 电子科技大学计算机科学与工程学院 hongweili@ /teacher/teacher.aspx?id=298 第4章 排序算法 排序的应用 Searching on unsorted data by comparing keys, optimal solutions require ?(n) comparisons. Searching on sorted data by comparing keys, optimal solutions require ?(log n) comparisons. Sorting data for users More… 排序问题 排序就是把一个无序集合中的元素按照一定顺序排列成线性结构。 例:将电话簿或字典的条目按字母表的顺序排列起来以便更有利于查找。 内部排序(internal sort):所有的数据都存储在计算机的高速随机存取存储器中,数据的读取时间可以忽略不计。 外部排序(external sort):对低速外存设备中存放的数据进行排序。 Insertion Sort Strategy: Insertion of an element in proper order: Begin with a sequence E of n elements in arbitrary order Initially assume the sorted segment contains the first element Let x be the next element to be inserted in sorted segment, pull x “out of the way”, leaving a vacancy repeatedly compare x to the element just to the left of the vacancy, and as long as x is smaller, move that element into the vacancy, else put x in the vacancy, repeat the next element that has not yet examined. Insertion Sort: e.g. Insertion Sort: Algorithm Input E, an array of elements, and n =0, the number of elements. The range of indexes is 0, …, n-1 Output E, with elements in nondecreasing order of their keys void insertionSort(Element[] E, int n) int xindex; for (xindex = 1; xindex n; xindex++) Element current = E[xindex]; key x = current.key int xLoc = shiftVacRec(E, xindex, x); E[xLoc] = current; return; Specification for subroutine Specification int shiftVacRec(Element[] E, int vacant, Key x) Precondition Vacant is nonnegative Postconditions 1. Elements in E at indexes less than xLoc are in their original positions and have keys less than or equal to x 2. Elements in E at positions xLoc+1, …, vacant are greater than x and were shifted up by one position from their positions when shiftVacRec was invoked. Algorithm shiftVacRec int shiftVacRec(Element[] E, int vacant, Key x) int xLoc; if (vacant == 0) xLoc = vacant; else if (E[vacant-1].key = x) xLoc = vacant; else E[vacant] = E[vacant-1]; xLoc = shiftVacRec(E, vaca
您可能关注的文档
- 硅酸盐热工基础---3.1(国)燃料性质讲述.ppt
- 硅酸盐第二课时讲述.ppt
- 硅酸钙板墙施工专项方案讲述.doc
- 第20讲排序2详解.pptx
- 社交礼仪2详解.ppt
- 第4章S7-200PLC基础知识详解.ppt
- 硅酸盐尘肺讲述.ppt
- 第22章《二次函数》期末复习(2016年)详解.docx
- 第23计远交近攻详解.ppt
- 社区商业的成功因素详解.docx
- 2025三支一扶模拟试题往年题考附答案详解.docx
- 2025三支一扶经典例题及答案详解(典优).docx
- 2025三支一扶综合提升测试卷(真题汇编)附答案详解.docx
- 2025三支一扶全真模拟模拟题附完整答案详解【考点梳理】.docx
- 2025三支一扶过关检测试卷及参考答案详解【满分必刷】.docx
- 2025三支一扶自我提分评估附参考答案详解【考试直接用】.docx
- 2025三支一扶考试黑钻押题含答案详解【轻巧夺冠】.docx
- 2025三支一扶模拟试题(预热题)附答案详解.docx
- 2025三支一扶综合提升测试卷带答案详解(名师推荐).docx
- 2024年社区工作人员题库检测试题打印【名校卷】附答案详解.docx
文档评论(0)