INTERMEDIATE⭐ Must Know 4 min read 4 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) |
⚡ Must Remember
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).
📐 Quick Revision Formula Sheet
Dijkstra & Prim (Binary Heap)
💡 With Fibonacci Heap: O(E + V log V)
Bellman-Ford & Kruskal
💡 DAG Shortest Path (even with negative weights): O(V + E)
#Graphs#Greedy#DP#Dijkstra#MST
🎯 Practice PYQs on This Topic (2)
Q1.GATE CS AlgorithmsMCQMEDIUM
+2 Marks • -0.67 NegWhat 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?
Q2.GATE CS AlgorithmsMCQMEDIUM
+2 Marks • -0.67 NegFive characters have frequencies . Using Huffman optimal prefix coding, what is the total weighted number of bits required to encode all characters?