Dijkstra s algorithm

21
Dijkstra's algorithm 1

Transcript of Dijkstra s algorithm

Page 1: Dijkstra s algorithm

1

Dijkstra's algorithm

Page 2: Dijkstra s algorithm

2

Single-Source Shortest Path Problem Single-Source Shortest Path Problem - The problem of finding shortest

paths from a source vertex v to all other vertices in the graph.

Page 3: Dijkstra s algorithm

3

Dijkstra's algorithm Dijkstra's algorithm - is a solution to the single-source shortest path problem in graph theory.  Works on both directed and undirected graphs. However, all edges must have nonnegative weights.

Approach: Greedy

Input: Weighted graph G={E,V} and source vertex v∈V, such that all edge weights are nonnegative Output: Lengths of shortest paths (or the shortest paths themselves) from a given source vertex v∈V to all other vertices

Page 4: Dijkstra s algorithm

4

Dijkstra's algorithm - Pseudocode

Page 5: Dijkstra s algorithm

5

Dijkstra Animated Example-1

Page 6: Dijkstra s algorithm

6

Dijkstra Animated Example-1

Page 7: Dijkstra s algorithm

7

Dijkstra Animated Example-1

Page 8: Dijkstra s algorithm

8

Dijkstra Animated Example-1

Page 9: Dijkstra s algorithm

9

Dijkstra Animated Example-1

Page 10: Dijkstra s algorithm

10

Dijkstra Animated Example-1

Page 11: Dijkstra s algorithm

11

Dijkstra Animated Example-1

Page 12: Dijkstra s algorithm

12

Dijkstra Animated Example-2

Page 13: Dijkstra s algorithm

13

Dijkstra Animated Example-2

Page 14: Dijkstra s algorithm

14

Dijkstra Animated Example-2

Page 15: Dijkstra s algorithm

15

Dijkstra Animated Example-2

Page 16: Dijkstra s algorithm

16

Dijkstra Animated Example-2

Page 17: Dijkstra s algorithm

17

Dijkstra Animated Example-2

Page 18: Dijkstra s algorithm

18

Dijkstra Animated Example-2

Page 19: Dijkstra s algorithm

19

Dijkstra Animated Example-2

Page 20: Dijkstra s algorithm

20

Dijkstra Animated Example-2

Shortest Path from A to H,A to C, C to D, D to E, E to G, G to F, F to H

Page 21: Dijkstra s algorithm

21

End