《算法入门》(英文版)Lecture 19 Prof. Erik Demaine

Introduction to algorithms 6.046J/18,401J/SMA5503 Lecture 19 Prof erik demaine
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine

Shortest paths Single-source shortest paths nonnegative edge weights Dijkstra's algorithm: O(E+ vlg n General Bellman-Ford: O(VE) DAg One pass of Bellman-Ford: O(+ E) All-pairs shortest paths Nonnegative edge weights Dijkstra's algorithm n times: O(VE+v2Ig n) General Three algorithms today c 2001 by Charles E Leiserson Introduction to Agorithms Day 32 L19.2
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.2 Shortest paths Single-source shortest paths • Nonnegative edge weights Dijkstra’s algorithm: O(E + V lg V) • General Bellman-Ford: O(VE) • DAG One pass of Bellman-Ford: O(V + E) All-pairs shortest paths • Nonnegative edge weights Dijkstra’s algorithm |V| times: O(VE + V 2 lg V) • General Three algorithms today

All-pairs shortest paths Input: Digraph G=(V, E), where v=n, with edge-weight function w: E>R Output: n x n matrix of shortest-path lengths 6(2 i for all i,j∈ IDEA #1 Run bellman-Ford once from each vertex Time =O(VZE Dense graph→O(4)time Good first try! c 2001 by Charles E Leiserson Introduction to Agorithms Day32L19.3
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.3 All-pairs shortest paths Input: Digraph G = (V, E), where |V| = n, with edge-weight function w : E → R. Output: n × n matrix of shortest-path lengths δ(i, j) for all i, j ∈ V. IDEA #1: • Run Bellman-Ford once from each vertex. • Time = O(V 2E). • Dense graph ⇒ O(V 4) time. Good first try!

Dynamic programming Consider the n x n adjacency matrix A=(a of the digraph, and define di m)=weight of a shortest path from i to that uses at most m edges Claim We have fo if i=j loo if i≠ and for m=1.2.. n-1 di(m)=mink dik (m-1)+ c 2001 by Charles E Leiserson Introduction to Agorithms Day 32 L19.4
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.4 Dynamic programming Consider the n × n adjacency matrix A = (aij) of the digraph, and define dij(0) = 0 if i = j, ∞ if i ≠ j; Claim: We have and for m = 1, 2, …, n – 1, dij(m) = mink{dik(m–1) + akj }. dij(m) = weight of a shortest path from i to j that uses at most m edges

Proof of claim d,i (m)=mingdik m-D)+aki) 1 edges Relaxation for kda,+ ikki then d tda+a ≤m-1 edges Note: No negative-weight cycles implies c 2001 by Charles E Leiserson Introduction to Agorithms Day 32 L19.5
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.5 Proof of claim dij ( m ) = min k { dik (m–1) + akj } ii j j M k’s ≤ m – 1 edges ≤ m – 1 edge s ≤ m – 1 edges ≤ m – 1 edges Relaxation! for k ← 1 to n do if dij > dik + akj then dij ← dik + akj Note: No negative-weight cycles implies δ ( i, j) = dij (n–1) = dij ( n) = dij (n+1) = L

Matrix multiplication Compute C=A·B, where C,A, and b are n×n matrices k=1 Time =0(n)using the standard algorithm What if we map“+”imin”and”->“+”? Cimino(aik+ buji Thus.Dm)=Dm-1)×A Identity matrix =I 0 0 c 2001 by Charles E Leiserson Introduction to Agorithms Day 32 L19.6
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.6 Matrix multiplication Compute C = A · B, where C, A, and B are n × n matrices: ∑ = = n k ij aik bkj c 1 . Time = Θ ( n 3) using the standard algorithm. What if we map “ + ” → “min” and “·” → “ +”? cij = min k { aik + bkj }. Thus, D ( m ) = D ( m–1) “ × ” A. Identity matrix = I = ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 0 0 0 0 = D 0 = ( dij(0) )

Matrix multiplication (continued) The(min, +)multiplication is associative, and with the real numbers it forms an algebraic structure called a closed semiring Consequently, we can compute D(1)=D0)·A=A1 0(2)=D D(n-1)=D(n-2)·A=A yielding D()=(&i, D) Time =o(n'n)=0(n). No better than n x B-F c 2001 by Charles E Leiserson Introduction to Agorithms Day 32 L19.7
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.7 Matrix multiplication (continued) The (min, +) multiplication is associative, and with the real numbers, it forms an algebraic structure called a closed semiring. Consequently, we can compute D(1) = D(0) · A = A1 D(2) = D(1) · A = A2 M M D(n–1) = D(n–2) · A = An–1 , yielding D(n–1) = (δ(i, j)). Time = Θ(n·n3) = Θ(n4). No better than n × B-F

Improved matrix multiplication algorithm Repeated squaring: A2k=Ak A' Compute A.A O(g n) squarings Note:An-1=An=An+1=… Time=o(nlgn To detect negative-weight cycles, check the diagonal for negative values in O(n) additional time c 2001 by Charles E Leiserson Introduction to Agorithms Day 32 L19.8
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.8 Improved matrix multiplication algorithm Repeated squaring: A2k = Ak × Ak. Compute A2, A4, …, A2lg(n–1) . O(lg n) squarings Time = Θ(n3 lg n). To detect negative-weight cycles, check the diagonal for negative values in O(n) additional time. Note: An–1 = An = An+1 = L

Floyd-warshall algorithm Also dynamic programming, but faster Define c, (k)= weight of a shortest path from i to i with intermediate vertices belonging to the set (1, 2,.,k Thus, 8(i,j=c (n). Also, Ciy c 2001 by Charles E Leiserson Introduction to Agorithms Day32L19.9
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.9 Floyd-Warshall algorithm Also dynamic programming, but faster! Define cij(k) = weight of a shortest path from i to j with intermediate vertices belonging to the set {1, 2, …, k}. ii ≤≤kk ≤≤kk ≤≤kk ≤≤kk jj Thus, δ(i, j) = cij(n). Also, cij(0) = aij

Floyd-warshall recurrence Ci()=mink ci(), cikk-D)+Ck(k-D) k (k-1) intermediate vertices in (1, 2,...,k c 2001 by Charles E Leiserson Introduction to Agorithms Dav32L19.10
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 32 L19.10 Floyd-Warshall recurrence cij(k) = mink {cij(k–1), cik(k–1) + ckj(k–1)} ii jj k cij(k–1) cik(k–1) ckj(k–1) intermediate vertices in {1, 2, …, k}
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《算法入门》(英文版)Lecture 18 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 17 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 16 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 15 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 14 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 13 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 12 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 11 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 10 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 9 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 8 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 7 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 6 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 5 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 4 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 3 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 2 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 1 Prof. Charles E. Leiserson.pdf
- 《城市设计实例—步行商业》杭州湖滨旅游商贸特色街区.ppt
- 《教育心理学》(英文版)Theories Operant Conditioning.ppt
- 《算法入门》(英文版)Lecture 20 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 21 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 22 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 23 Prof. Charles E. Leiserson.pdf
- 《加快林业建设—缓解气候变化》讲义.ppt
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Alkene/Alkyne Hydrozirconation.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Olefin functionalization via metal promoted Nu attack.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Murai has described the synthesis.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)π-Trimethylenemethane cyclization.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Functionalization of terminal olefins.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Course Overviewweek1.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Ligand Exchange Mechanisms.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)C-C Bond Formation.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Sonogashira:in situ, metal assisted deprotonation.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Wilkinson's original.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Substrate-directed hydrogenations with.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Monohydride catalysts.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)The Holy Grail of Catalysis.pdf
- 《建筑施工图的绘制》第五讲 建筑图纸的表达.ppt
- 21 世纪高职高专会计专业主干课程:《管理会计》PPT教学课件(共十章).ppt