Unweighted Shortest Paths Unweighted Shortest Paths Dijkstra's Algorithm
Unweighted Shortest Paths Unweighted Shortest Paths Dijkstra's Algorithm
Announcement
Lab exam will take place on May 17 2011 17, Tuesday, at 6:30pm
Shortest-Path Algorithms
Th i The input i a weighted graph: associated t is i ht d h i t d with each edge (vi, vj) is a cost ci,j. The cost of a path v1v2...vN is ci,i+1 for i in v [1..N-1]. This is weighted path length, the unweighted path length on the other hand is merely the number of edges on p , y, the path, namely, N-1. Single-source Shortest-Path Problem: p g graph ( , ), Given as input a weighted g p G=(V, E), and a distinguished vertex, s, find the shortest weighted path from s to every other vertex in G th t i G.
Izmir University of Economics 3
Complexity O(|V|2)
Izmir University of Economics 8
Unweighted Shortest Paths - Improvement At any point in time there y yp are only two types of unknown vertices that have dv. Some have dv = currDist and the rest have dv = currDist +1. We can make use of a queue data structure structure. O(|E|+|V|)
Izmir University of Economics 9
11
A proof by contradiction will show that this algorithm always works as long as no edge has a negative cost cost.
Izmir University of Economics 12
13
16
Acyclic Graphs
If the graph is known to be acyclic, the order in which vertices are declared known, can be set to be the topological order. Running time = O(|V|+|E|) This selection rule works because when a vertex is selected, its distance can no longer be lowered, since by topological lowered ordering rule it has no incoming edges emanating from unknown nodes nodes.
Izmir University of Economics 17