in Algorithms edited by
1,929 views
1 vote
1 vote
For prim's algorithm array implementation takes $O(V^2)$ while min heap implementation takes $O((E+V)\log V)$ time. For dense graph $E = O(V^2).$

So is array implementation considered better or the min heap one???

Does the min heap implementation run better for graph with less edges??
in Algorithms edited by
by
1.9k views

1 Answer

3 votes
3 votes
Best answer
For dense graph $E=O(V^2)$

Prim's Algorithm with Min heap takes $O((E+V)\log V)$ time

Array implementation takes $O(V^2)$

So, for dense graph

Min heap takes $O((V^2+V)\log V) = O(V^2 \log V)$ which is asymptotically more than $O(V^2)$

For sparse graphs, $E = O(V)$ and the time complexities for binary heap and array implementations will be $O(V \log V)$ and $O(V^2)$ respectively.

 So, heap implementation is suitable for sparse graphs and array implementation for dense graphs.
selected by

Related questions

0 votes
0 votes
1 answer
1