Aspect | Prim's Algorithm | Kruskal's Algorithm |
---|---|---|
Starting point | Starts with a single vertex | Starts with all vertices and no edges |
Edge selection | Adds the cheapest edge from the current vertex | Adds the cheapest edge that does not form a cycle |
Data structure | Priority queue (min-heap) | Disjoint-set data structure |
Time complexity | O(V^2) or O((V + E) log V) | O(E log E) |
Suitability | Dense graphs | Sparse graphs |
Implementation | More complex | Simpler |