All-Pairs Shortest Paths

Slides:



Advertisements
Similar presentations
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
Advertisements

: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
1 Q10276: Hanoi Tower Troubles Again! 星級 : ★★★ 題組: Online-judge.uva.es PROBLEM SET Volume CII 題號: Q10276: Hanoi Tower Troubles Again! 解題者:薛祖淵 解題日期: 2006.
3Com Switch 4500 切VLAN教學.
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
: Determine it 星等:★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10520: Determine it 解題者:林祺光 解題日期: 2006 年 5 月 22 日 題意:給兩個值 a 1,n 和 n a i,j.
: Factstone Benchmark ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: : Factstone Benchmark 解題者:鐘緯駿 解題日期: 2006 年 06 月 06 日 題意: 假設 1960.
亂數產生器安全性評估 之統計測試 SEC HW7 姓名:翁玉芬 學號:
: Road Construction ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 10724: Road Construction 解題者:徐文宏 解題日期: 2011 年 4 月 20 日 題意:給一個座標圖 (-1000~1000)
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
Graph V(G 1 )={0, 1, 2, 3, 4, 5, 6, 7, 8, 9} E(G 1 )={(0, 2), (0, 3), (1, 4), (2, 3), (2, 5), (2, 6), (3, 6), (3, 7), (4, 7), (5, 6), (5,
:New Land ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11871: New Land 解題者:施博修 解題日期: 2011 年 6 月 8 日 題意:國王有一個懶兒子,為了勞動兒子,他想了一個 辦法,令他在某天早上開始走路,直到太陽下山前,靠.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
: ShellSort ★★☆☆☆ 題組: Problem D 題號: 10152: ShellSort 解題者:林一帆 解題日期: 2006 年 4 月 10 日 題意:烏龜王國的烏龜總是一隻一隻疊在一起。唯一改變烏龜位置 的方法為:一隻烏龜爬出他原來的位置,然後往上爬到最上方。給 你一堆烏龜原來排列的順序,以及我們想要的烏龜的排列順序,你.
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
8.1 何謂高度平衡二元搜尋樹 8.2 高度平衡二元搜尋樹的加入 8.3 高度平衡二元搜尋樹的刪除
: The Playboy Chimp ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10611: The Playboy Chimp 解題者:蔡昇宇 解題日期: 2010 年 2 月 28 日 題意:給一已排序的數列 S( 升冪.
Department of Air-conditioning and Refrigeration Engineering/ National Taipei University of Technology 模糊控制設計使用 MATLAB 李達生.
第一章 演算法:效率、分析與量級 1.1演算法 1.2發展有效率演算法的重要性 1.3演算法的分析 1.4量級(Order)
具備人臉追蹤與辨識功能的一個 智慧型數位監視系統 系統架構 在巡邏模式中 ,攝影機會左右來回巡視,並 利用動態膚色偵測得知是否有移動膚色物體, 若有移動的膚色物體則進入到追蹤模式,反之 則繼續巡視。
1 第四章 多變數函數的微分學 § 4.1 偏導數定義 定義 極限值 ■. 2 定理 極限值的基本定理 (1) 極限值的唯一性 : 若 存在,則 其值必為唯一。 (2) 若 且 ( 與 為常數 ) , 則 且 為常數且.
Chapter 13 塑模靜態觀點:物件圖 Static View : Object Diagram.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
: The Scrooge Co Problem ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11047: The Scrooge Co Problem 解題者:鍾正一 解題日期: 2007 年 6 月 5 日 題意:輸入 X.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
Chapter 20 塑模動態觀點:狀態圖 Statechart Diagram. 學習目標  說明狀態圖的目的  定義狀態圖的基本記號  展示狀態圖的建構  定義活動、內部事件及遞延事件的狀態 圖記號.
: Tight words ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: : Tight Words 解題者:鐘緯駿、林一帆 解題日期: 2006 年 03 月 14 日 題意: 給定數字 k 與 n (0 ≦ k.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
7.1 背景介紹 7.2 多解析度擴展 7.3 一維小波轉換 7.4 快速小波轉換 7.5 二維小波轉換 7.6 小波封包
Johnson’s algorithm Johnson’s演算法可用於計算All pairs shortest path問題。
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
短缺,盈餘與均衡. 遊戲規則  老師想出售一些學生喜歡的小食。  老師首先講出價錢,有興趣買的請舉手。
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
最短路徑演算法 卓訓榮 2002/11/11 Data base Label Setting Algorithm Label Correcting Algorithm 運輸資訊.
Single-Source Shortest Paths
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
Lecture 7 Sorting in Linear Time. Sorting in Linear Time2 7.1 Lower bounds for sorting 本節探討排序所耗用的時間複雜度下限。 任何一個以比較為基礎排序的演算法,排序 n 個元 素時至少耗用 Ω(nlogn) 次比較。
Chapter 26 Maximum Flow 流量網路與流量 Flow network( 流量網路 ) G=(V,E) 是一個有向圖, 每一邊 (u,v) ∈ E 均有 Capacity( 容量 ) c(u,v)>0 。如 c(u,v)=0 即代表 (u,v) ∉ E 。 s v1v1.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
Chapter 26 Maximum Flow 流量網路與流量 Flow network( 流量網路 ) G=(V,E) 是一個有向圖, 每一邊 (u,v) ∈ E 均有 Capacity( 容量 ) c(u,v)>0 。如 c(u,v)=0 即代表 (u,v) ∉ E 。 s v1v1.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
: A-Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10930: A-Sequence 解題者:陳盈村 解題日期: 2008 年 5 月 30 日 題意: A-Sequence 需符合以下的條件, 1 ≤ a.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
函式 Function Part.2 東海大學物理系‧資訊教育 施奇廷. 遞迴( Recursion ) 函式可以「呼叫自己」,這種動作稱為 「遞迴」 此程式的執行結果相當於陷入無窮迴圈, 無法停止(只能按 Ctrl-C ) 這給我們一個暗示:函式的遞迴呼叫可以 達到部分迴圈的效果.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
: Expect the Expected ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11427: Expect the Expected 解題者:李重儀 解題日期: 2008 年 9 月 21 日 題意:玩一種遊戲 (a game.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Learning Method in Multilingual Speech Recognition Author : Hui Lin, Li Deng, Jasha Droppo Professor: 陳嘉平 Reporter: 許峰閤.
Chapter 10 m-way 搜尋樹與B-Tree
演算法課程 (Algorithms) 國立聯合大學 資訊管理學系 陳士杰老師 Course 7 貪婪法則 Greedy Approach.
1 523: Minimum Transport Cost ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 523: Minimum Transport Cost 解題者:林祺光 解題日期: 2006 年 6 月 12 日 題意:計算兩個城市之間最小的運輸成本,運輸.
Probability Distribution 機率分配 汪群超 12/12. 目的:產生具均等分配的數值 (Data) ,並以 『直方圖』的功能計算出數值在不同範圍內出現 的頻率,及繪製數值的分配圖,以反應出該 機率分配的特性。
: Help My Brother ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11033: Help My Brother 解題者: 呂明璁 解題日期: 2007 年 5 月 14 日.
: Mini Cube ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11007: Mini Cube 解題者:郭峻維 解題日期: 2007 年 3 月 27 日 題意:找出 2x2x2 的 Rubik‘s cube 的最佳解。
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
: Wine trading in Gergovia ★★☆☆☆ 題組: Contest Volumes with Online Judge 題號: 11054: Wine trading in Gergovia 解題者:劉洙愷 解題日期: 2008 年 2 月 29 日 題意:在 Gergovia.
:Commandos ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11463: Commandos 解題者:李重儀 解題日期: 2008 年 8 月 11 日 題意: 題目會給你一個敵營區內總共的建築物數,以及建築物 之間可以互通的路有哪些,並給你起點的建築物和終點.
11 Ch05 遞迴 淡江大學 周清江 1. 2  遞迴函數乃是一個自己反覆呼叫自己的函數  一個典型的遞迴演算法 n! = n * (n-1)! = n * (n-1) * (n-2)! = n * (n-1) * (n-2) * (n-3)! = … = n * (n-1) * (n-2)
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
: Construct the wall maze ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11050: Construct the wall maze 解題者:宋柏儀 解題日期: 2007 年 6 月 12 日.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Rings and Glue ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10301: Rings and Glue 解題者:施博修 解題日期: 2011 年 5 月 18 日 題意:小約翰有了個大麻煩,他不小心將 rings.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
Activity Networks AOV 網路 AOE 網路. AOV 網路 (Activity on Vertx Networks)  為了表示一件工作中,各子工程間的先後 關係,我們可以利用有向圖中的有向邊代 表事情進行的順序,位於一條有向邊終點 的事件必須要等待起點的事情完成後,才 可以進行。
Presentation transcript:

All-Pairs Shortest Paths

All-Pairs Shortest Paths 15.1 最短路徑的特性 最短路徑的結構: 所有最短路徑的子路徑均為最短路徑。 如:(vi,…,vk,vj)為vi到vj的最短路徑,則(vi,…,vk)必為vi到vk的最短路徑。 即:δ(vi,vj)=δ(vi,vk)+w(vk,vj) All-Pairs Shortest Paths

All-Pairs Shortest Paths 最短路徑的特性 一個直覺的遞迴解: 定義d(m)(i,j)為包含至多m個邊自ij的最短路徑長度。則: All-Pairs Shortest Paths

All-Pairs Shortest Paths 利用遞迴解計算出最短路徑 令n=|V|,如一圖無負迴圈,則d(n-1)(i,j)即為ij的最短路徑長度。 可以直覺使用動態規劃的方式來求出解,但耗時O(|V|3log|V|)反不如直接利用Dijkstra演算法直接求出所有點作為起點到其他點的最短路徑(以Linear array實做耗時O(|V|3))。 All-Pairs Shortest Paths

All-pairs Shortest Paths演算法 輸入: 一無負迴圈圖G=(V,E),|V|=n。 n×n adjacency matrix W=(W[i,j]) All-Pairs Shortest Paths

All-pairs Shortest Paths演算法 輸出: n×n minimum distance matrix D=(D[i,j]) D[i,j]=δ(i,j) n×n predecessor matrix π=(π[i,j]) 若ij無路徑則π[i,j]=NIL, 否則π[i,j]紀錄ij最短路徑上j之前的點 π[i,j] i k j All-Pairs Shortest Paths

All-Pairs Shortest Paths Extend-Shortest-Paths(D,W) { nrows[D] Let D’ = (D’[i,j]) be an nn matrix for i=1 to n do for j=1 to n do D’[i,j] for k=1 to n do D’[i,j]min(D’[i,j],D[i,k]+W[k,j]) return D’ } Extended-Shortest-Paths耗時O(n3) 而Slow-All-Pairs-Shortest-Paths則是利用遞迴式, 用O(n)次的Extended-Shortest-Paths來計算出D(n-1) Time Complexity: O(n3) All-Pairs Shortest Paths

All-Pairs Shortest Paths Slow-All-Pairs-Shortest-Paths(G,W) { n|V| D(1)W for m=2 to n-1 do D(m)Extend-Shortest-Paths(D(m-1),W) return D(n-1) } Time Complexity: O(n4) All-Pairs Shortest Paths

All-Pairs Shortest Paths Faster-All-Pairs-Shortest-Paths(G,W) { n|V| D(1)=W m=1 while n-1>m do D(2m)Extend-Shortest-Paths(D(m),D(m)) m = 2m return D(m) } 此即O(n3logn)的直覺遞迴解推得的動態規劃演算法。 利用遞迴性質,可以將Extended-Shortest-Paths呼叫次數減低到logn次。 Time Complexity: O(n3logn) All-Pairs Shortest Paths

All-Pairs Shortest Paths 15.2 Floyd-Warshall演算法 主要利用不同的觀察找出新的遞迴式,使得演算法複雜度降低至O(n3),在邊數多的時候能有比Dijkstra演算法更迅速的求出所有的最短路徑。 若一ij的路徑為(i,u1,…,um,j),則我們稱u1,…,um為該路徑的Intermediate vertex(中間點)。 d(0)(i,j)的初始化係可能存在有路徑而無中間點。 如果i=j則可推出最短距離0, 反之,則取決於是否有邊相連, 有邊相連,則為該邊之weight, 無邊相連則視為無限大,故等同於w(i,j)。 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall演算法 假定點集合V={1,…,n},定義d(m)(i,j)為中間點僅可能為{1,…,m}最短的ij路徑長。故: All-Pairs Shortest Paths

Floyd-Warshall演算法正確性分析 考慮中間點僅可能為{1,…,k}。 如k不在ij最短路徑上,則中間點僅可能為{1,…,k-1},故此時:d(k)(i,j)=d(k-1)(i,j)。 All-Pairs Shortest Paths

Floyd-Warshall演算法正確性分析 如k在ij最短路徑上,則將ik及kj兩段分開看,這兩個路徑必然不可能有中間點為k,否則依照無負迴圈的假定,ik或kj不是最短路徑,違背最短路徑的性質。故此時: d(k)(i,j)=d(k-1)(i,k)+d(k-1)(k,j)。 中間點僅有 {1,…,k-1} i k j 中間點僅有 {1,…,k-1} All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall演算法 Floyd-Warshall(G,W) { n|V| D(0)W for k = 1 to n do for i = 1 to n do for j = 1 to n do if D(k-1)[i,j]>D(k-1)[i,k]+D(k-1)[k,j] then D(k)[i,j]D(k-1)[i,k]+D(k-1)[k,j] π[i,j] π[k,j] else D(k)[i,j]D(k-1)[i,j] return D(n) } Time Complexity: O(n3) All-Pairs Shortest Paths

All-Pairs Shortest Paths 初始化π[i,j]時,如i=j或(i,j)∉E則初始為NIL,否則初始為i。 等執行完演算法後,則可利用Single-Source shortest path的方式,藉由Predecessor graph來建立出ij的最短路徑。 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 1 3 -4 8 7 5 2 6 2 4 1 4 3 -5 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 All-Pairs Shortest Paths

All-Pairs Shortest Paths Floyd-Warshall範例 All-Pairs Shortest Paths

All-Pairs Shortest Paths 15.3 Johnson’s algorithm Johnson’s演算法可用於計算All pairs shortest path問題。 在邊的數量不多的時候,如|E|=O(|V|log|V|)時,能有比Warshall-Floyd演算法較佳的效能。 其輸入需求是利用Adjacency list表示的圖。 All-Pairs Shortest Paths

All-Pairs Shortest Paths Johnson’s algorithm Johnson’s 演算法利用reweighing來除去負邊,使得該圖可以套用Dijkstra演算法,來達到較高的效能。 Reweighing是將每個點v設定一個高度h(v),並且調整邊的weight function w(u,v)成為w’(u,v)=w(u,v)+h(u)-h(v)。 令δ‘(u,v)如此調整之後的最短距離,則原先的最短距離δ(u,v)=δ‘(u,v)-h(u)+h(v)。 All-Pairs Shortest Paths

All-Pairs Shortest Paths Johnson’s algorithm Johnson(G) { compute G’, where V[G’]=V[G]{s} and E[G’]=E[G]{(s,v):vV[G] if Bellman-Ford(G’,w,s)=False then print “ a neg-weight cycle” else for each vertex v V[G’] set h(v)=(s,v) computed by Bellman-Ford algo. for each edge (u,v)E[G’] w’(u,v)=w(u,v)+h(u)-h(v) for each vertex u V[G] run Dijkstra(G,w’,u) to compute ’(u,v) for each v V[G] duv=’(u,v)-h(u)+h(v) return D } All-Pairs Shortest Paths

Johnson’s algorithm範例 4 3 7 8 -5 1 -4 2 6 All-Pairs Shortest Paths

Johnson’s algorithm範例 加入一個點s,以及自s拉一條weight為0的邊到每一點。 4 3 7 8 s -5 1 -4 2 6 All-Pairs Shortest Paths

Johnson’s algorithm範例 -1 執行Bellman-Ford演算法,得到自s出發每一點的最短距離。 4 3 7 8 s -5 -5 1 -4 2 -4 6 All-Pairs Shortest Paths

Johnson’s algorithm範例 -1 做完reweighting 4 10 13 -5 2 -4 2 All-Pairs Shortest Paths

Johnson’s algorithm範例 2/1 紅線部分是Shortest-paths tree。 點的數字a/b代表自出發點(綠色點)出發,到達該點的最短路徑(Reweighting後的圖/原圖)。 4 10 13 0/0 2/-3 2 0/-4 2/0 2 All-Pairs Shortest Paths

Johnson’s algorithm範例 0/0 4 10 13 2/3 0/-4 2 2/-1 0/1 2 All-Pairs Shortest Paths

Johnson’s algorithm範例 0/4 4 10 13 2/7 0/0 2 2/3 0/5 2 All-Pairs Shortest Paths

Johnson’s algorithm範例 0/-1 4 10 13 2/2 0/-5 2 2/-2 0/0 2 All-Pairs Shortest Paths

Johnson’s algorithm範例 2/5 4 10 13 4/8 2/1 2 0/0 2/6 2 All-Pairs Shortest Paths

Johnson’s algorithm複雜度分析 執行一次Bellman-Ford。O(|V||E|)。 執行|V|次Dijkstra。 使用Fibonacci heap,總計O(|V|2log|V|+|V||E|) 。 使用Binary heap,總計O(|V||E|log|V|)。 當|E|足夠小,比Warshall-Floyd快。 All-Pairs Shortest Paths