∑GateAndNet
Practice MCQs
GATE CS / Algorithms
Edit
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

AlgorithmProblemNegative Weights Allowed?Time Complexity
BFSUnweighted Shortest PathN/AO(V+E)\mathcal{O}(V + E)
DAG RelaxationSingle-Source on DAGYesO(V+E)\mathcal{O}(V + E)
DijkstraSingle-Source Shortest PathNoO((V+E)log⁡V)\mathcal{O}((V+E)\log V)
Bellman-FordSingle-Source + Neg Cycle CheckYesO(V⋅E)\mathcal{O}(V \cdot E)
Floyd-WarshallAll-Pairs Shortest PathYesO(V3)\mathcal{O}(V^3)
Kruskal / PrimMinimum Spanning TreeYes! (MST works on negative edges)O(Elog⁡V)\mathcal{O}(E \log V)
⚡ Must Remember

MST Uniqueness Theorem:

  • If all edge weights in GG 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)
O((V+E)log⁡V)=O(Elog⁡V) for connected graphs\mathcal{O}((V + E)\log V) = \mathcal{O}(E \log V) \text{ for connected graphs}
💡 With Fibonacci Heap: O(E + V log V)
Bellman-Ford & Kruskal
Bellman-Ford: O(V⋅E),Kruskal: O(Elog⁡E)=O(Elog⁡V)\text{Bellman-Ford: } \mathcal{O}(V \cdot E), \qquad \text{Kruskal: } \mathcal{O}(E \log E) = \mathcal{O}(E \log V)
💡 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 Neg

What is the worst-case time complexity of Dijkstra’s single-source shortest path algorithm on a graph G=(V,E)G = (V, E) implemented using a Binary Min-Heap adjacency list?

Q2.GATE CS AlgorithmsMCQMEDIUM
+2 Marks • -0.67 Neg

Five characters have frequencies 5,9,12,13,165, 9, 12, 13, 16. Using Huffman optimal prefix coding, what is the total weighted number of bits required to encode all 5555 characters?

Previous TopicAsymptotic Notation & Master Theorem for Divide-and-ConquerNext Topic Dynamic Programming Masterclass: 0/1 Knapsack, LCS & Matrix Chain Multiplication