Dijkstra s algorithm

Post on 12-Jan-2017

191 views 0 download

Transcript of Dijkstra s algorithm

1

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.

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

4

Dijkstra's algorithm - Pseudocode

5

Dijkstra Animated Example-1

6

Dijkstra Animated Example-1

7

Dijkstra Animated Example-1

8

Dijkstra Animated Example-1

9

Dijkstra Animated Example-1

10

Dijkstra Animated Example-1

11

Dijkstra Animated Example-1

12

Dijkstra Animated Example-2

13

Dijkstra Animated Example-2

14

Dijkstra Animated Example-2

15

Dijkstra Animated Example-2

16

Dijkstra Animated Example-2

17

Dijkstra Animated Example-2

18

Dijkstra Animated Example-2

19

Dijkstra Animated Example-2

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

21

End