10-11-01ADA08(分治法-大整数、矩阵相乘)课件.ppt
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《10-11-01ADA08(分治法-大整数、矩阵相乘)课件.ppt》由用户(ziliao2023)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 10 11 01 ADA08 分治 整数 矩阵 相乘 课件
- 资源描述:
-
1、2023-5-122010-2011-01 Design and Analysis of Algorithm SCUECReview of last classbThe difference between quick sort and merge sort Divide step Combine step Stable or not In place or not Time efficiencybQuick sort algorithmDivide and Conquer(III)Chapter 4l Application to numerical problemn Large integ
2、ers multiplicationn Matrices multiplicationl Application to combinatorial problemn Tromino puzzle2023-5-142010-2011-01 Design and Analysis of Algorithm SCUECGoals of the LecturebAt the end of this lecture,you should Understand the algorithm based on DAC for solving large integers multiplication and
3、its analysis Master the Strassens matrix multiplication algorithm and its analysis2023-5-152010-2011-01 Design and Analysis of Algorithm SCUECMultiplication of Large Integers The grade-school algorithm:a1 a2 an b1 b2 bn (d10)d11d12 d1n (d20)d21d22 d2n (dn0)dn1dn2 dnnConsider the problem of multiplyi
4、ng two(large)n-digit integers represented by arrays of their digits such as:A=12345678901357986429 B=87654321284820912836Efficiency:n2 one-digit multiplications.too inefficient!2023-5-162010-2011-01 Design and Analysis of Algorithm SCUECStandard Algorithm based on DACA=B=Where:A=A1*10n/2+A2 B=B1*10n
5、/2+B2 A B=A1 B110n+(A1 B2+A2 B1)10n/2+A2 B2A1B1B2A2bSuppose the n-digits of the two integers is a power of 2,i.e.n=2k,then we can divide them as follows:b Efficiency:T(n)=4T(n/2),T(1)=1 Solution:T(n)=n2 bA small example:A=2135 and B=4014 no improvement!2023-5-172010-2011-01 Design and Analysis of Al
6、gorithm SCUECImproved Algorithm based on DACbIn order to improve the time complexity,the numbers of multiplication must be decreased.bTwo solutions:A B=A1 B110n+(A1+A2)*(B1+B2)-A1 B1-A2 B2)10n/2+A2 B2 A B=A1 B110n+(A1-A2)*(B2 B1)+A1 B1+A2 B2)10n/2+A2 B2b Efficiency:T(n)=3T(n/2),T(1)=1 Solution:T(n)=
7、nlog3 bigger improvement!A B=A1 B110n+(A1 B2+A2 B1)10n/2+A2 B22023-5-182010-2011-01 Design and Analysis of Algorithm SCUECvoid MATRIX_MULTIPLY(float An,float Bn,float Cn)for(int i=0;in;i+)for(int j=0;jn;j+)Cii=Ai0*B0j;for(k=1;k=2 T(1)=1bIn fact,the recursive version requires n3 multiplications and n
8、3 n2 additions,so it is not more efficient than the standard one.On the contrary,it is cost more in terms of both time and space brought by recursion.bT(n)=n3+(n3-n2)2023-5-1122010-2011-01 Design and Analysis of Algorithm SCUECStrassens Matrix MutiplicationbUses a set of seven formulas to multiply t
9、wo 22 matricesbThe formulas do not rely on elements being commutative under multiplication,so the elements can be matrices bIt can be applied recursively,in other words,two 4 4 matrices can be multiplied by treating each as a 2 2 matrix of 2 2 matrices2023-5-1132010-2011-01 Design and Analysis of Al
10、gorithm SCUECStrassens Formulas(I)bFirst we calculate a set of temporary values:m1=(A1,1+A2,2)*(B1,1+B2,2)m2=(A2,1+A2,2)*B1,1m3=A1,1*(B1,2-B2,2)m4=A2,2*(B2,1-B1,1)m5=(A1,1+A1,2)*B2,2m6=(A2,1-A1,1)*(B1,1+B1,2)m7=(A1,2-A2,2)*(B2,1+B2,2)111211121112212221222122,=AABBCCAHCAABBCC2023-5-1142010-2011-01 De
11、sign and Analysis of Algorithm SCUECStrassens Formulas(II)bCan you write out the strassens algorithm?(description)1111122111121222111221112221211222222122A BA BA BA BCCCA BA BA BA BCCbThe result is then calculated by:C1,1=m1+m4-m5+m7 C2,1=m2+m4C1,2=m3+m5C2,2=m1+m3-m2+m62023-5-1152010-2011-01 Design
12、and Analysis of Algorithm SCUECAlgorithm analysisbThese formulas require 7 multiplications and 18 additions to multiply two 2 2 matricesbThe real savings occur when this is applied recursively and we do approximately n2.81 multiplications and 6n2.81-6n2 additionsbThough not used in practice,Strassen
13、s method is important because it was the first algorithm that is faster than O(n3)T(n)=7T(n/2)+18(n/2)2 if n=2 T(1)=1 T(n)=nlog7+6nlog7 6n22023-5-1162010-2011-01 Design and Analysis of Algorithm SCUECStandard vs DAC vs Strassen6n2.81-6n2n2.81Strassens algorithmn3Standard algorithm based on DACn3-n2n
展开阅读全文