Nptel Mooc, Jan-Feb 2015 Week 4, Module 1: Design and Analysis of Algorithms
Nptel Mooc, Jan-Feb 2015 Week 4, Module 1: Design and Analysis of Algorithms
Week 4, Module 1
70
3 4
80 6
50
1 2 5 6
10 20
10 5
7
Shortest path problems
Single source
All pairs
70
3 4
80 6
50
1 2 5 6
10 20
10 5
7
Single source shortest paths
Imagine vertices are oil depots, edges are pipelines
Single source shortest paths
70
3 4
80 6
50
1 2 5 6
10 20
10 5
7
Single source shortest paths
70
3 4
80 6
50
1 2 5 6
10 20
t=0 10 5
7
Single source shortest paths
70
3 4
80 6
50
1 2 5 6
10 20
t=0 10 5
t = 10
7
Single source shortest paths
t = 16
70
3 4
80 6
50
1 2 5 6
10 20
t=0 10 5
t = 10
7
Single source shortest paths
t = 16
70
3 4
80 t = 30
6
50
1 2 5 6
10 20
t=0 10 5
t = 10
7
Single source shortest paths
t = 16
70
3 4
80 t = 30
6
50
1 2 5 6
10 20
t=0 10 5
t = 10
7
t = 40
Single source shortest paths
t = 16
70
3 4
80 t = 30 t = 45
6
50
1 2 5 6
10 20
t=0 10 5
t = 10
7
t = 40
Single source shortest paths
t = 16 t = 86
70
3 4
80 t = 30 t = 45
6
50
1 2 5 6
10 20
t=0 10 5
t = 10
7
t = 40
Single source shortest paths
Compute expected time to burn of each vertex
70
3 4
80 6
50
1 2 5 6
10 20
10 5
7
Single source shortest paths
Compute expected time to burn of each vertex
Set ExpectedBurnTime[1] = 0
EBT[s] = 0
for i = 1 to n
Choose u such that BV[u] == False
and EBT[u] is minimum
BV[u] = True
for each edge (u,v) with BV[v] == False
if EBT[v] > EBT[u] + weight(u,v)
EBT[v] = EBT[u] + weight(u,v)
Dijkstras algorithm
function ShortestPaths(s){ // assume source is s
for i = 1 to n
Visited[i] = False; Distance[i] = infinity
Distance[s] = 0
for i = 1 to n
Choose u such that Visited[u] == False
and Distance[u] is minimum
Visited[u] = True
for each edge (u,v) with Visited[v] == False
if Distance[v] > Distance[u] + weight(u,v)
Distance[v] = Distance[u] + weight(u,v)