- 1、本文档共34页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
如何设计一个时间复杂度量级较低的演算法是我们必须一直摆在心中
Floor and ceiling Modular arithmetic For any integer a and any positive integer n, the value a mod n is the remainder (or residue) of the quotient a/n : a mod n =a -?a/n?n. If(a mod n) = (b mod n). We write a ? b (mod n) and say that a is equivalent to b, modulo n. We write a ? b (mod n) if a is not equivalent to b modulo n. Analyzing Algorithms Based on: 物件導向資料結構 — 使用Java語言, 江振瑞 著, 松崗圖書公司, 2005. Introduction to the Design and Analysis of Algorithms -- A strategic approach, 2E, R.C.T. Lee et. al., NcGraw Hill, 2005. Introduction to Algorithms, Cormen et. al., MIT Press. Analyzing algorithms Analyzing an algorithm has come to mean predicting the resources that the algorithm requires. Resources: memory, communication, bandwidth, logic gate, time. We usually assume that the algorithm is performed on a processor with RAM Analyzing algorithms The running time of an algorithm on a particular input is the number of primitive operations or “steps” executed. It is convenient to define the notion of step so that it is as machine-independent as possible Complexity 一般我們使用 時間複雜度(time complexity) 空間複雜度(space complexity) 來評估演算法的執行時間與所佔用記憶體空間, 這些複雜度愈低,則表示演算法愈好。 我們比較關注time complexity! Three Cases 演算法的時間複雜度分析分為以下三種: 最佳狀況(best case)時間複雜度:考慮演算法執行時所需要的最少執行步驟數。 最差狀況(worst case)時間複雜度:考慮演算法執行時所需要的最多執行步驟數。 平均狀況(average case)時間複雜度:考慮所有可能狀況下演算法的平均執行步驟數。 Usually, we concentrate on finding only on the worst-case running time Reason: ?It is an upper bound on the running time ?The worst case occurs fair often The average case is often as bad as the worst case. For example, the insertion sort. Again, quadratic function. Worst-case and average-case analysis An Alg. for Testing Primes 我們可以看出,輸入大於2的任意正整數n,若n是質數,則演算法Prime1需要執行整數除法求餘數(n%i)動作與整數比較((n%i)=0)動作n-2次之後,才可以知道n是質數。另外,若n不是質值,則演算法Prime1只要執行整數除法求餘數與整數比較動作1次,就可以知道n不是質數了。 Algorithm Prime1(n):Input:一個大於2的正整數nOutput:true或false(表示n是質數或不是質數)for i←2 to n-1 do if (n%i)=0 then return falsereturn true 我們可以看出,輸入大於2的任意正整數n,若n是質數,則演算
您可能关注的文档
- 采用资源划分的云环境下hadoop资源许可调度方法-中国云计算.pdf
- 教改教案-三重积分6课时.doc
- 教育部台南县联络处95学年军训工作执行计画-教育部台南联络.ppt
- 是德科技测量解决方案之nfc器件测试-keysight.pdf
- 年学年下学期赴大陆交换学生心得报告.pdf
- 肯塔基食品法典修改自2010年5月1日起生效.pdf
- 样本请特别注意其中的英文字母大小写及标点符号的-应用力学学报.pdf
- 数据页3rm1103aa04.pdf
- 地震救援装备检测规程液压动力工具-中国地震信息网.pdf
- 大学生社团生命力的群体动力学分析-中国社会科学网.pdf
- (高清版)DB62∕T 4290-2021 法定计量检定机构监督检查规范.docx
- (高清版)DB62∕T 4382-2021 玉米品种 垦玉90.docx
- (高清版)DB62∕T 3228-2022 泥石流工程防治技术规程.docx
- (高清版)DB62∕T 4343-2021 公路路基压实质量动态模量检测技术规程.docx
- (高清版)DB62∕T 3217-2022 沉管灌注桩施工技术规程.docx
- (高清版)DB62∕T 4284.5-2021 绿色矿山建设规范 第5部分:砂石粘土矿.docx
- (高清版)DB62∕T 4339-2021 高速公路工地试验室标准化指南.docx
- (高清版)DB62∕T 4292-2021 绿色食品 滑子菇生产技术规程.docx
- (高清版)DB62∕T 4344-2021 公路改性沥青SBS改性剂含量检测技术规程.docx
- (高清版)DB62∕T 4412-2021 水萝卜设施栽培技术规程.docx
文档评论(0)