0% found this document useful (0 votes)
23 views21 pages

3.4 (Extra) Dijkstra Demo

The document describes Dijkstra's shortest path algorithm using an example graph. It shows the algorithm finding the shortest path from a start node 's' to all other nodes. It initializes the priority queue with all nodes and their initial distances. It then repeatedly extracts the node with the lowest distance from the priority queue, adds it to the set of visited nodes, and updates the distances of its neighbors if a shorter path is found.

Uploaded by

amit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views21 pages

3.4 (Extra) Dijkstra Demo

The document describes Dijkstra's shortest path algorithm using an example graph. It shows the algorithm finding the shortest path from a start node 's' to all other nodes. It initializes the priority queue with all nodes and their initial distances. It then repeatedly extracts the node with the lowest distance from the priority queue, adds it to the set of visited nodes, and updates the distances of its neighbors if a shorter path is found.

Uploaded by

amit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

DIJKSTRA'S SHORTEST PATH

ALGORITHM - EXAMPLE

1
Dijkstra's Shortest Path Algorithm
Find shortest path from s to t.

24
2 3
9

s
18
14
2 6
6
30 4 19
11
15 5
5
6
20 16

t
7 44

2
Dijkstra's Shortest Path Algorithm
S={ }
PQ = { s, 2, 3, 4, 5, 6, 7, t }



24
2 3
0 9

s
18
14  2 6
6 
30  4 19
11
15 5
5
6
20 16

t
7 44
distance label  
3
Dijkstra's Shortest Path Algorithm
S={ }
PQ = { s, 2, 3, 4, 5, 6, 7, t }

delmin


24
2 3
0 9

s
18
14  2 6
6 
30  4 19
11
15 5
5
6
20 16

t
7 44
distance label  
4
Dijkstra's Shortest Path Algorithm
S={s}
PQ = { 2, 3, 4, 5, 6, 7, t }

decrease key


 9
X
24
2 3
0 9

s
18
14 X
 14 6
2
6 
30  4 19
11
15 5
5
6
20 16

t
7 44
distance label  15
X 
5
Dijkstra's Shortest Path Algorithm
S={s}
PQ = { 2, 3, 4, 5, 6, 7, t }

delmin


X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
30  4 19
11
15 5
5
6
20 16

t
7 44
distance label  15
X 
6
Dijkstra's Shortest Path Algorithm
S = { s, 2 }
PQ = { 3, 4, 5, 6, 7, t }



X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
30  4 19
11
15 5
5
6
20 16

t
7 44

 15
X 
7
Dijkstra's Shortest Path Algorithm
S = { s, 2 }
PQ = { 3, 4, 5, 6, 7, t }

decrease key

 33
X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
30  4 19
11
15 5
5
6
20 16

t
7 44

 15
X 
8
Dijkstra's Shortest Path Algorithm
S = { s, 2 }
PQ = { 3, 4, 5, 6, 7, t }

 33
X

X 9
24
2 3
0 9
delmin
s
18
14 X 14
 6
2
6 
30  4 19
11
15 5
5
6
20 16

t
7 44

 15
X 
9
Dijkstra's Shortest Path Algorithm
S = { s, 2, 6 }
PQ = { 3, 4, 5, 7, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 
10
Dijkstra's Shortest Path Algorithm
S = { s, 2, 6 }
PQ = { 3, 4, 5, 7, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X delmin 
11
Dijkstra's Shortest Path Algorithm
S = { s, 2, 6, 7 }
PQ = { 3, 4, 5, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 
59 X
12
Dijkstra's Shortest Path Algorithm
S = { s, 2, 6, 7 }
PQ = { 3, 4, 5, t } delmin

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 
59 X
13
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 6, 7 }
PQ = { 4, 5, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 51 59
X X
14
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 6, 7 }
PQ = { 4, 5, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16
delmin

t
7 44

 15
X 51 59
X X
15
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 5, 6, 7 }
PQ = { 4, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
45 X
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 50 51
X 59 
X X
16
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 5, 6, 7 }
PQ = { 4, t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
45 X
X 34
X 35
44
30 X
 4 19
11
15 5 delmin
5
6
20 16

t
7 44

 15
X 50 51
X 59 
X X
17
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 4, 5, 6, 7 }
PQ = { t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
45 X
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 50 51
X 59 
X X
18
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 4, 5, 6, 7 }
PQ = { t }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
45 X
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X
delmin 50 51
X 59 
X X
19
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 4, 5, 6, 7, t }
PQ = { }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
45 X
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 50 51
X 59 
X X
20
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 4, 5, 6, 7, t }
PQ = { }

32
 33
X X

X 9
24
2 3
0 9

s
18
14 X 14
 6
2
6 
45 X
X 34
X 35
44
30 X
 4 19
11
15 5
5
6
20 16

t
7 44

 15
X 50 51
X 59 
X X
21

You might also like