Graph Theory37 sections · 1633 units
Open in Course

Prim's Time Complexity

(Heap operations dominate)

Prim's time complexity is O(ElogV)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+VlogV)O(E + V \log V), which is better for dense graphs.

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

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