Dijkstra's Algorithm
Dijkstra's Algorithm
By Deekshant
What is Dijkstra's algorithm
Dijkstra's algorithm is an algorithm for finding the
shortest path between two nodes in a graph. It uses
greedy approach to find the shortest path.
How it works
Suppose we have a graph containing 5 nodes and some
connected edges with given weight and we want to
find the shortest path from start to end.
6
A B
5
1 2
2 C
5
E D
1
Start
End
6
Shortest Previous
A B Vertex Distance Vertex
5 From A
A 0
2
1 2 C B ∞
C ∞
5 D ∞
E D
1 E ∞
A 0
2
1 2 C B ∞
C ∞
5 D ∞
E D
1 E ∞
A 0
2
1 2 C B 6 A
C ∞
5 D ∞
E D
1 E 1 A
0 + 1
A 0
2
1 2 C B 3 E
C ∞
5 D 2 E
E D
1 E 1 A
1 + 1
5 D 2 E
E D
1 E 1 A
5 D 2 E
E D
1 E 1 A
A 0
2
1 2 C B 3 E
C 7 D
5 D 2 E
E D
1 E 1 A
A 0
2
1 2 C B 3 E
C 7 D
5 D 2 E
E D
1 E 1 A
A 0
2
1 2 C B 3 E
C 7 D
5 D 2 E
E D
1 E 1 A
A 0
2
1 2 C B 3 E
C 7 D
5 D 2 E
E D
1 E 1 A
Cons
• Not efficient for large graphs
• Greedy approach
• Blinds search causes more time
Thank You.