You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
In unweighted graphs, BFS finds the shortest path. But many real-world graphs have weighted edges — roads have distances, network links have latencies, and pipelines have capacities. Dijkstra's algorithm finds the shortest path from a single source to all other vertices in a graph with non-negative edge weights.
Given a weighted graph and a source vertex, find the shortest (minimum total weight) path from the source to every other vertex.
Example: In a road network, find the shortest driving distance from your home to every other location.
Dijkstra's algorithm maintains a distance table and a priority queue (or a simple unvisited set). It works as follows:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.