100 likes | 297 Views
The single-source shortest path problem. 許智凱. The Single-Source Shortest Path Problem. The single-source shortest path problem 是要用來尋找所有由同一個源點到達圖上每一個節點的最短路徑 . 給予一個連接的有向圖形 G =( V , E ), 且每條邊的權重皆不為負值 . This weight can be considered as the length of this edge.
E N D
The Single-Source Shortest Path Problem • The single-source shortest path problem是要用來尋找所有由同一個源點到達圖上每一個節點的最短路徑. • 給予一個連接的有向圖形G=(V,E),且每條邊的權重皆不為負值. This weight can be considered as the length of this edge. • 由於是要尋找最短路徑,等同於花費最少的成本到達每個節點,同為Greedy method.
The Single-Source Shortest Path Problem • Shortest paths from v0 to all of the other vertices are found one by one. The nearest neighbor of v0 is first found. Then the second nearest neighbor of v0 is found. This processis repeated until the nth nearest neighbor of v0 is found where n is the number of vertices in the graph other than v0.
Source set: S Vertices - S: V-S
Dijkstra’s Algorithm Input:有向圖G= (V, E) 與源點v0. 取得與v0相連每 個點的邊上權重c. |V|= n + 1. Output: 對於每個vÎ V, 所取得的權重最小值 S: = {v0} Fori : = 1 to n do Begin If (v0, vi) ÎE then L(vi) : = c(v0, vi) else L(vi) : = ¥ End
Dijkstra’s Algorithm For i : = 1 to n do Begin Choose u from V - S such that L(u) is thesmallest S : = S ∪{u} (* Put u into S *) For all w in V - S do L(w) : = min(L(w), L(u) + c(u, w)) End
Example: 01234 30 0 0 2 01030 4 0102530 010253029 4 15 10 10 10 1 3 20
Example: ABCDE 0 10 3 2 B D 0 7 3 11 5 10 0 7 3 9 5 A 4 8 9 3 C E 2
Time Complexity • Time = Ω(V·取得連接邊的權重c +E·比較最小權重邊並取代) Binary Heap: V·logV+E·logV → E· logV Fibonacci Heap: (E+ V· logV) E