INTERMEDIATECore Topic 4 min read 19 views
Shortest Path & MST Algorithms: Dijkstra, Bellman-Ford, Prim & Kruskal
Edge relaxation, negative edge traps, Disjoint-Set Union Kruskal complexity, and MST uniqueness theorem.
Shortest Path & MST Master Comparison
| Algorithm | Problem | Negative Weights Allowed? | Time Complexity |
|---|---|---|---|
| BFS | Unweighted Shortest Path | N/A | |
| DAG Relaxation | Single-Source on DAG | Yes | |
| Dijkstra | Single-Source Shortest Path | No | |
| Bellman-Ford | Single-Source + Neg Cycle Check | Yes | |
| Floyd-Warshall | All-Pairs Shortest Path | Yes | |
| Kruskal / Prim | Minimum Spanning Tree | Yes! (MST works on negative edges) |
Important
MST Uniqueness Theorem:
- If all edge weights in are distinct, the Minimum Spanning Tree is guaranteed to be unique!
- Conversely, a unique MST does not require all edge weights to be distinct (e.g., a tree with equal weights has a unique MST).
Key Formulas Summary
Dijkstra & Prim (Binary Heap)
Note: With Fibonacci Heap: O(E + V log V)
Bellman-Ford & Kruskal
Note: DAG Shortest Path (even with negative weights): O(V + E)
#Graphs#Greedy#DP#Dijkstra#MST
Practice Questions on This Chapter (3)
Q1GATE CS AlgorithmsMCQMEDIUM
+2M • -0.67
What is the worst-case time complexity of Dijkstra’s single-source shortest path algorithm on a graph implemented using a Binary Min-Heap adjacency list?
⚡ Click an option above to verify instantly
Q2GATE CS AlgorithmsMCQMEDIUM
+2M • -0.67
Five characters have frequencies . Using Huffman optimal prefix coding, what is the total weighted number of bits required to encode all characters?
⚡ Click an option above to verify instantly
Q3GATE CS 2020NATMEDIUM
+2M • 0 Neg
The complete undirected graph ( labeled vertices) has how many distinct Spanning Trees (by Cayley’s Formula)?