Course5切割与征服Divide-and-Conquer-联合大学.ppt

Course5切割与征服Divide-and-Conquer-联合大学.ppt

  1. 1、本文档共27页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Algorithms (Dr. Shi-Jay Chen, National United University) Course 5 切割與征服 Divide-and-Conquer ▓ Outlines 本章重點 Divide-and-Conquer策略的描述 Binary Search Merge Sort The Divide-and-Conquer Approach Quick Sort Strassens Matrix Multiplication Algorithm When Not to Use Divide-and-Conquer ▓ Divide-and-Conquer策略的描述與技巧 The divide-and-conquer approach is a top-down approach. It divides a problem into two or more smaller problems. The smaller problems are usually instances of the original problem. If solutions to the smaller problems can be obtained readily, the solution to the original problem can be obtained by combining these solutions. If the smaller problems are still too large to be solved readily, they can be divided into still smaller problems. This process of dividing the problems continues until they are so small that a solution is readily obtainable. Def: 可將母問題切割成較小的問題 (切割),使用相同的解決程序加以處理 (征服)。所有小問題的解可以成為母問題的最後解; 若有必要,則再將每個小問題的處理結果加以合併,就可以得到最後的答案。 由於使用相同的解決程序處理每個小問題,這一個程序就會被遞迴呼叫,因此一個遞迴演算法則通常以一個副程式的型式出現,內部包含一個解決程序與遞迴呼叫。 對於具有遞迴關係的問題,或是一些採用遞迴定義的資料結構,都適合採用Divide-and-Conquer演算法設計策略 最簡潔、易懂 效率差 (∵採用遞迴設計) Divide-and-Conquer使用時機 下列兩種情況是適合使用Divide-and-Conquer設計策略 (也是遞迴演算法的適用時機): 問題本身具有遞迴關係 母問題可被切割成較小的 “相同” 問題 如: 階乘問題、費氏數問題、河內塔問題、快速排序問題、二元搜尋問題…等 資料結構屬於遞迴定義 大量的Data Set,在切割後仍為一組具 “相同性質” 的Data Set 如: 二元樹 (Binary Tree)、鏈結串列 (Link List)…等 遞迴演算法則的設計 找出問題的終止條件. 找出問題本身的遞迴關係 (遞迴呼叫). 技巧: 思考遞迴呼叫需要哪些參數? 遞迴呼叫的傳回值為何? 遞迴呼叫的終止條件為何? 終止傳回何值? ▓ Binary Search (二分搜尋) 實施前提: 檔案中記錄須事先由小到大排序過 須由Random (或Direct) access之機制支援 (e.g., Array) 觀念: 每次皆與Search範圍的中間記錄進行比較!! while ( l ? u ) 比較 (k, S[m]) case “=”: found, i = m, return i; case “”: u = m-1; case “”: l = m+1; recurn 0; 分析 利用Time function T(n) = T(n/2) + O(1) = T(n/2) + c = (T(n/4 + c)) + c = T(n/4) + 2c = (T(n/8) + c) + 2c = T(n/8) +3c = … = T(n/n) + log2n?c = T(1) + c log2n (T(1) = 1, c 為大於 0 的常數) = 1 + c log2n ? T(n) = O(log2n)

您可能关注的文档

文档评论(0)

jinchenl + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档