dijkstra's shortest path algorithm

20
1 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6

Upload: cagatay-yuksel

Post on 05-Dec-2014

1.620 views

Category:

Education


6 download

DESCRIPTION

A demonstration of Dijkstra's Shortest Path Algorithm by example

TRANSCRIPT

Page 1: Dijkstra's Shortest Path Algorithm

1

Dijkstra's Shortest Path Algorithm

Find shortest path from s to t.

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

Page 2: Dijkstra's Shortest Path Algorithm

2

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

0

distance label

S = { }PQ = { s, 2, 3, 4, 5, 6, 7, t }

Page 3: Dijkstra's Shortest Path Algorithm

3

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

0

distance label

S = { }PQ = { s, 2, 3, 4, 5, 6, 7, t }

delmin

Page 4: Dijkstra's Shortest Path Algorithm

4

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

distance label

S = { s }PQ = { 2, 3, 4, 5, 6, 7, t }

decrease key

X

X

X

Page 5: Dijkstra's Shortest Path Algorithm

5

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

distance label

S = { s }PQ = { 2, 3, 4, 5, 6, 7, t }

X

X

X

delmin

Page 6: Dijkstra's Shortest Path Algorithm

6

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2 }PQ = { 3, 4, 5, 6, 7, t }

X

X

X

Page 7: Dijkstra's Shortest Path Algorithm

7

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2 }PQ = { 3, 4, 5, 6, 7, t }

X

X

X

decrease key

X 33

Page 8: Dijkstra's Shortest Path Algorithm

8

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2 }PQ = { 3, 4, 5, 6, 7, t }

X

X

X

X 33

delmin

Page 9: Dijkstra's Shortest Path Algorithm

9

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 6 }PQ = { 3, 4, 5, 7, t }

X

X

X

X 33

44X

X

32

Page 10: Dijkstra's Shortest Path Algorithm

10

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 6 }PQ = { 3, 4, 5, 7, t }

X

X

X

44X

delmin

X 33X

32

Page 11: Dijkstra's Shortest Path Algorithm

11

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 6, 7 }PQ = { 3, 4, 5, t }

X

X

X

44X

35X

59 X

24

X 33X

32

Page 12: Dijkstra's Shortest Path Algorithm

12

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 6, 7 }PQ = { 3, 4, 5, t }

X

X

X

44X

35X

59 X

delmin

X 33X

32

Page 13: Dijkstra's Shortest Path Algorithm

13

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 6, 7 }PQ = { 4, 5, t }

X

X

X

44X

35X

59 XX 51

X 34

X 33X

32

Page 14: Dijkstra's Shortest Path Algorithm

14

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 6, 7 }PQ = { 4, 5, t }

X

X

X

44X

35X

59 XX 51

X 34

delmin

X 33X

32

24

Page 15: Dijkstra's Shortest Path Algorithm

15

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 5, 6, 7 }PQ = { 4, t }

X

X

X

44X

35X

59 XX 51

X 34

24

X 50

X 45

X 33X

32

Page 16: Dijkstra's Shortest Path Algorithm

16

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 5, 6, 7 }PQ = { 4, t }

X

X

X

44X

35X

59 XX 51

X 34

24

X 50

X 45

delmin

X 33X

32

Page 17: Dijkstra's Shortest Path Algorithm

17

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 4, 5, 6, 7 }PQ = { t }

X

X

X

44X

35X

59 XX 51

X 34

24

X 50

X 45

X 33X

32

Page 18: Dijkstra's Shortest Path Algorithm

18

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 4, 5, 6, 7 }PQ = { t }

X

X

X

44X

35X

59 XX 51

X 34

X 50

X 45

delmin

X 33X

32

24

Page 19: Dijkstra's Shortest Path Algorithm

19

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 4, 5, 6, 7, t }PQ = { }

X

X

X

44X

35X

59 XX 51

X 34

X 50

X 45

X 33X

32

Page 20: Dijkstra's Shortest Path Algorithm

20

Dijkstra's Shortest Path Algorithm

s

3

t

2

6

7

4

5

24

18

2

9

14

15 5

30

20

44

16

11

6

19

6

15

9

14

0

S = { s, 2, 3, 4, 5, 6, 7, t }PQ = { }

X

X

X

44X

35X

59 XX 51

X 34

X 50

X 45

X 33X

32