You are on page 1of 24

DIJKSTRA’S ALGORITHM

(AN EXAMPLE)
to

from

A is the origin
Not immediately
connected

Subscript A shows that most


recently came from A
I have got the shortest path from A
to C so I do not have to worry about
C as a destination. So I put a square
around it
My shortest path to D comes through C
and it has a weight of 4
They are the same . It does not matter which one we pick as the
smallest. Let us choose the first one as it occurs in alphabetical
order.
If I want to know what the path is which vertices it
went through, I just start at the destination. For
example, lets say I wanted to know about this path of 6
(weight) to vertex G; it came most recently from E so it
ended with EG. The vertex E had the shortest path to it
from D so it went through DEG and so prior to D it
came from C and from there previously it came from A.
so it went from A to C to D to E and then from E to G.
And so that is the path we had to take to get to the
length of 6 i.e. 2+2+1+1=6 and we can do the same
thing for any one of these minimal weight paths that
are now in boxes.
Minimum paths from MINIMUM PATHS
Node A to other
nodes
A to B ACDB
A to C AC
A to D ACD
A to E ACDE
A to F ACDEGF
A to G ACDEG
A to H ACDEGFH
B

A C D E G F H

Minimum Path tree for Node A

You might also like