Dijkstra's Algorithm
Dijkstra's Algorithm
A.Harshini K.Sanjana
221IT006 221IT041
Dijkstra’s:
It Allows us to Find the shortest path between any two vertices of a graph.
It differs from the minimum spanning tree because the shortest distance
between two vertices might not include all vertices of the graph.
HOW IT WORKS?
Approach:Greedy (To find single source shortest path)
Time complexity:O(V^2)
Space Complexity:O(v)
Example:
A student wants to go from home to school in the
shortest possible way. She knows some roads are
heavily congested and difficult to use. In Dijkstra's
algorithm, this means the edge has a large
weight/cost and the shortest path tree found by
the algorithm will try to avoid edges with larger
weights. If the student looks up directions using a
map service, it is likely they may use Dijkstra's
algorithm.
return dist[] // Return the array containing distances from source to all vertices
Thank You...