shortest path algorithm this is called “dijkstra’s algorithm” …pronounced “dirk-stra”

7
Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk- stra”

Upload: brenda-watkins

Post on 27-Dec-2015

226 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

Shortest Path Algorithm

This is called “Dijkstra’s Algorithm”

…pronounced “Dirk-stra”

Page 2: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

Problem:

F

E

D

C

B

A

8

3

49

5

7

5

9

Find the shortest route from A to F

Page 3: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

Step 1 Label the start vertex S with a permanent label of 0

Step 2 Put a temporary label on each vertex that can be reached directly

from the vertex that has just received a permanent label. The

temporary label must be equal to the sum of the permanent label and the weight of the arc linking it directly to the vertex. If there is already a temporary label at the vertex, it is only replaced if the new sum is smaller.

Page 4: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

Step 3 Select the minimum temporary label and make it permanent. Step 4 Repeat steps 2 and 3 until the

destination vertex T receives its permanent label.

Step 5 Trace back from T to S including an arc AB whenever the

permanent label of B permanent label of A = the weight of AB, given that B already lies on the path.

Page 5: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

Vertex Letter

Order of Selectio

n

Final Values

Working Values

Each vertex will have a box like the one below which has to be filled in:

Page 6: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

Problem:

F

E

D

C

B

A

8

3

49

5

7

5

9

Find the shortest route from A to F

On the exam paper your diagram will look like this:

Page 7: Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”

8

73

4

59

9

5

A

B

C

D

E

F

First vertex is A

1

Label 0

0

Temporary Labels

7

4

Second vertex is C

2

Label 4

4

13

13

Third vertex is B

3

Label 7

715

but 15 > 13 so ignore

Fourth vertex is E

4

Label 12

12

12

17

Fifth vertex is D

5

Label 13

13

16

6

Sixth vertex is F

Label 16

16

Now trace back from F16 – 13 = 3 so use DF13 – 9 = 4 so use CD4 – 0 = 4 so use AC

Shortest Path is ACDF of length 16