Medium Algorithms Graph Algorithms
Compare Kruskal's and Prim's algorithms for Minimum Spanning Tree.
Answer
Both find MST but differ in approach. Kruskal's: sort all edges, add smallest edge that doesn't form cycle (using Union-Find). Time O(E log E). Better for sparse graphs and when edges are already sorted. Prim's: grow tree from arbitrary vertex, always add minimum edge connecting tree to non-tree vertex. Time O(E log V) with binary heap. Better for dense graphs. Both are greedy algorithms guaranteed to find MST.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Software Engineer Algorithm Developer Network Engineer