CSAlgorithms & ComplexityDiagramIntermediate
Dijkstra's Algorithm
KO: 다익스트라 알고리즘·EN: Dijkstra's Algorithm·JA: ダイクストラ法
A greedy shortest-path algorithm for non-negative weighted graphs using a priority queue to find optimal distances in O((V+E) log V) time
Table of Contents
Structure Diagram
Dijkstra Shortest Path Edge RelaxationTap a node
ROOTStart A (0)
2 linksQuick Answer
What is Dijkstra's Algorithm?
A greedy shortest-path algorithm for non-negative weighted graphs using a priority queue to find optimal distances in O((V+E) log V) time. It is a core concept in Algorithms & Complexity within CS.
Core Principles
Dijkstra's Algorithm computes the shortest path from a single source to all other vertices in a weighted graph with non-negative edge weights.
- Greedy Extraction & Relaxation: Pop the closest unvisited vertex
ufrom a min-heap, then relax each outgoing edge(u, v, w): ifdist[u] + w < dist[v], updatedist[v]and push to the heap. - Complexity:
O((V + E) log V)with an adjacency list and binary heap. - Non-Negative Requirement: Negative edges break the greedy assumption that popped vertices are final (use Bellman-Ford instead).
Practical Takeaways
- Skip stale heap entries: Rather than implementing decrease-key, push updated
(dist, node)pairs and ignore popped entries whered > dist[u]. - Early exit & A extension*: Stop immediately once the target node is popped; add an admissible heuristic (like Euclidean distance) to upgrade to A* for spatial routing.
- Use BFS for unit weights: If every edge costs 1, plain BFS runs faster in
O(V + E)without heap overhead.
Notable Examples
- GPS Navigation: Computing fastest routes over weighted road segments.
- OSPF Network Routing: Calculating lowest-cost packet forwarding tables across routers.
- Flight & Logistics Routing: Minimizing travel cost or transfer latency.