Dijkstra's Algorithm
Dijkstra's Algorithm
Report Issue
“Dijkstra’s algorithm” solves the “single-source shortest path” problem in a weighted directed
graph with non-negative weights.
Video Explanation
In the next video, we'll explain how to solve the “single-source shortest path” problem using
Dijkstra's Algorithm.
next video.
The “greedy approach” only guarantees that, at each step, it takes the optimal choice in the
current state. It does not guarantee that the final result is optimal. So, how does “Dijkstra’s
Algorithm” ensure that its final result is optimal?
https://leetcode.com/explore/learn/card/graph/622/single-source-shortest-path-algorithm/3862/ 2/3
05/10/2024, 16:10 Explore - LeetCode
Complexity Analysis
V represents the number of vertices, and E represents the number of edges.
Time Complexity: O(E + V log V ) when a Fibonacci heap is used, or O(V + E log V ) for
a Binary heap.
If you use a Fibonacci heap to implement the “min-heap”, extracting minimum element
will take O(log V ) time while key decreasing operation will take amortized O(1) time,
therefore, the total time complexity would be O(E + V log V ).
If you use a Binary heap, then the time complexity would be O(V + E log V ).
Space Complexity: O(V ). We need to store V vertices in our data structure.
https://leetcode.com/explore/learn/card/graph/622/single-source-shortest-path-algorithm/3862/ 3/3