麻省理工大学算法导论lecture19

麻省理工大学算法导论lecture19

ID:33830590

大小:159.83 KB

页数:14页

时间:2019-02-28

麻省理工大学算法导论lecture19_第1页
麻省理工大学算法导论lecture19_第2页
麻省理工大学算法导论lecture19_第3页
麻省理工大学算法导论lecture19_第4页
麻省理工大学算法导论lecture19_第5页
资源描述:

《麻省理工大学算法导论lecture19》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、IntroductiontoAlgorithms6.046J/18.401J/SMA5503Lecture19Prof.ErikDemaineShortestpathsSingle-sourceshortestpaths•Nonnegativeedgeweights≠Dijkstra’salgorithm:O(E+VlgV)•General≠Bellman-Ford:O(VE)•DAG≠OnepassofBellman-Ford:O(V+E)All-pairsshortestpaths•Nonnegativeedgeweights≠Dijkstra’salgori

2、thm

3、V

4、times:O(VE+V2lgV)•General≠Threealgorithmstoday.©2001byCharlesE.LeisersonIntroductiontoAlgorithmsDay32L19.2All-pairsshortestpathsInput:DigraphG=(V,E),where

5、V

6、=n,withedge-weightfunctionw:E→R.Output:n×nmatrixofshortest-pathlengthsδ(i,j)foralli,j∈V.IDEA#1:•RunBellman-Fordoncefromeac

7、hvertex.•Time=O(V2E).•Densegraph⇒O(V4)time.Goodfirsttry!©2001byCharlesE.LeisersonIntroductiontoAlgorithmsDay32L19.3DynamicprogrammingConsiderthen×nadjacencymatrixA=(a)ijofthedigraph,anddefined(m)=weightofashortestpathfromijitojthatusesatmostmedges.Claim:Wehave(0)0ifi=j,d=ij∞ifi≠j;andf

8、orm=1,2,…,n–1,d(m)=min{d(m–1)+a}.ijkikkj©2001byCharlesE.LeisersonIntroductiontoAlgorithmsDay32L19.4Proofofclaimk’sd(m)=min{d(m–1)+a}ijkikkjsegde1–m≤segde1–mi≤jii≤jm–1MedgeRelaxation!sfork←1tondoifd>d+aijikkjthendij←dik+akj≤m–1edgesNote:Nonegative-weightcyclesimpliesδ(i,j)=d(n–1)=d(n)=

9、d(n+1)=Lijijij©2001byCharlesE.LeisersonIntroductiontoAlgorithmsDay32L19.5MatrixmultiplicationComputeC=A·B,whereC,A,andBaren×nmatrices:ncij=∑aikbkj.k=1Time=Θ(n3)usingthestandardalgorithm.Whatifwemap“+”→“min”and“·”→“+”?c=min{a+b}.ijkikkjThus,D(m)=D(m–1)“×”A.0∞∞∞∞0∞∞0(0)Identitymatri

10、x=I=∞∞0∞=D=(dij).∞∞∞0©2001byCharlesE.LeisersonIntroductiontoAlgorithmsDay32L19.6Matrixmultiplication(continued)The(min,+)multiplicationisassociative,andwiththerealnumbers,itformsanalgebraicstructurecalledaclosedsemiring.Consequently,wecancomputeD(1)=D(0)·A=A1D(2)=D(1)·A=A2MMD(n–

11、1)=D(n–2)·A=An–1,yieldingD(n–1)=(δ(i,j)).Time=Θ(n·n3)=Θ(n4).Nobetterthann×B-F.©2001byCharlesE.LeisersonIntroductiontoAlgorithmsDay32L19.7ImprovedmatrixmultiplicationalgorithmRepeatedsquaring:A2k=Ak×Ak.242lg(n–1)ComputeA,A,…,A.O(lgn)squaringsNote:An–1=An=An+1=L.Time=Θ(n3lgn).Todetect

12、negat

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。