网站大量收购闲置独家精品文档,联系QQ:2885784924

03-分治策略全解.ppt

  1. 1、本文档共64页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
03-分治策略全解

复杂性分析 * 递推关系式 T(n)=O(nlogn) Thanks! * Choosing the pivot 1. Divide the n elements into groups of 5. Choosing the pivot 2. Find the median of each 5-element group. Choosing the pivot Choosing the pivot Choosing the pivot Choosing the pivot Minor simplification Analysis of Alg. SELECT Running Time T(n)= Θ (n) Conclusions Since the work at each level of recursion is a constant fraction (19/20) smaller, the work per level is a geometric series dominated by the linear work at the root. In practice, this algorithm runs slowly, because the constant in front of n is large. The randomized algorithm is far more practical. * 5 大整数乘法(Large Integer Multiplication) Complex multiplication. (a + bi) (c + di) = x + yi. Grade-school. x = ac - bd, y = bc + ad. Gauss method. x = ac - bd, y = (a + b) (c + d) - ac - bd. Remark. Improvement if no hardware multiply. 4 ultiplications, 2 additions 3 multiplications, 5 additions * Integer Arithmetic Add. Given two n-bit integers a and b, compute a + b. Grade-school. Θ(n) bit operations. Multiply. Given two n-bit integers a and b, compute a * b. Grade-school. Θ(n2) bit operations. * Multiply two n-bit integers x = (10ma +b), y = (10mc +d), m=n/2 x y = (10ma +b) (10mc +d) Example: x = 1234567890, m=5, a=12345, b=67890 Multiply four n/2-bit integers. ac, bc, ad, bd Add and shift to obtain result. x y = 102mac + 10m(bc +ad)+ bd * 分治算法伪代码 Alg. Multiply (x, y, n) If n = 1 return x*y; Else m = n/2; a = x/10m, b = x mod 10m; c = y/10m, d= y mod 10m; e = Multiply(a, c,m); f = Multiply(b, d, m); g = Multiply(b, c, m); h = Multiply(a, d, m); Reutrn 102m*e + 10m* (g+h) +f; * Running Time of Alg. Multiply T(n) = 4T(n/2) + O(n) T(1) = 1 Which solves to T(n) = O(n2) by the master theorem. Fast multiply: Anatolii, Karatsuba in 1962: x y = 102mac + 10m(bc +ad)+ bd T(n) = 3 T(n/2) + O(n) T(n) = O(nlg3)=O(n1.585) bc + ad = ac+ bd - (a - b

您可能关注的文档

文档评论(0)

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

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

1亿VIP精品文档

相关文档