cse 780 algorithms advanced algorithms sssp dijkstra’s algorithm sssp in dags
Post on 21-Dec-2015
231 views
TRANSCRIPT
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
CSE 780 Algorithms
Directed Acyclic Graphs
SSSPs in DAGs, allowing negative weights
Can be done in O(|V| + |E|)
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
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.
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.
CSE 780 Algorithms
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CSE 780 Algorithms
Pseudo-code
Only d[s] = 0in Q
If d[v] improves during the Relax operation, do Decrease-key(Q, v, d[v])
CSE 780 Algorithms
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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
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