Download presentation
Presentation is loading. Please wait.
1
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs
2
CSE 780 Algorithms Review Given edge (u,v) (s,v) ≤ (s,u) + w(u,v) Relax(u,v,w) If d[u] = (s,u) before the operation Then d[v] = (s,v) Path relaxation property
3
CSE 780 Algorithms Directed Acyclic Graphs SSSPs in DAGs, allowing negative weights Can be done in O(|V| + |E|)
4
CSE 780 Algorithms Pseudo-code Time complexity: O(|V| + |E|)
5
CSE 780 Algorithms Example
6
CSE 780 Algorithms Correctness Claim: d[v] = (s, v) at termination Assume is the shortest path Relax happens in order of path Therefore claim is true by Path-Relaxation property = v = s
7
CSE 780 Algorithms Shortest-Paths Problem A shortest-paths problem, given a weighted, directed graph G=(V,E) with weight function w: E→ R, is to find the shortest path between two arbitrary vertices, u and v. This problem is a generalization of BFS to handle weighted graphs. Edge weights can be interpreted, instead of as distances, as time, cost, etc.
8
CSE 780 Algorithms Dijkstra’s Algorithm Given directed graph G=(V,E), with only non- negative weights Bear similarity to breadth-first search and Prim’s algorithm Maintain a set S V whose shortest-path from source s have already been determined. Use a min-priority queue Q to store V-S, keys are the shortest path weight estimate d[v] Repeatedly select next vertex from V-S, and add it to S.
9
CSE 780 Algorithms INIT-SINGLE-SOURCE(V,s) For each vertex v ε V do d[v] ←∞ л[v] ← NIL d[s] ← 0
10
CSE 780 Algorithms Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
11
CSE 780 Algorithms Pseudo-code Only d[s] = 0 in Q If d[v] improves during the Relax operation, do Decrease-key(Q, v, d[v])
12
CSE 780 Algorithms Example
13
CSE 780 Algorithms Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
14
CSE 780 Algorithms Analysis Time complexity: #Extract-min: O(|V|) #Decrease-key = #Relax: O(|E|) Use binary heap for priority heap: Time complexity: O((|V| + |E|) log |V|) Use Fibonacci heap for priority heap: Amortized time complexity: O(|V| log |V| + |E|) Greedy algorithm: Any moment, select the lightest vertex in V-S to add to set S
15
CSE 780 Algorithms Correctness Claim: At the start of each iteration of the while loop, d[v] = (s, v) for each vertex v S. Proof: (by contradiction) Let u be the first vertex d[u] (s,u) when added to S Must be a shortest path from s to u
16
CSE 780 Algorithms Remarks Similar to breadth-first search, It adds nodes into S in order of their distance to s The algorithm also induces a shortest-paths tree Why is non-negative weights required? Example?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.