Graph Theory37 sections · 1633 units
Open in Course

Prim's Time Complexity

(Heap operations dominate)

Prim's time complexity is O(Elog⁡V)O(E \log V) with a binary heap, where EE is edges and VV is nodes. You push each edge once and pop at most VV times from the heap. With a Fibonacci heap, Prim runs in O(E+Vlog⁡V)O(E + V \log V), which is better for dense graphs.

But binary heaps are simpler and usually fast enough. For sparse graphs (E≈VE \approx V), Prim and Kruskal have similar performance. For dense graphs (E≈V2E \approx V^2), Prim can be faster.

Space complexity is O(V)O(V) for the data structures used.