Open In App

Time and Space Complexity Analysis of Prim’s Algorithm

The time complexity of Prim’s algorithm is O(V2) using an adjacency matrix and O((V +E) log V) using an adjacency list, where V is the number of vertices and E is the number of edges in the graph. The space complexity is O(V+E) for the priority queue and O(V2) for the adjacency matrix representation. The algorithm’s time complexity depends on the data structure used for storing vertices and edges, impacting its efficiency in finding the minimum spanning tree of a graph.

Aspect Complexity
Time Complexity O((V + E) log V)
Space Complexity O(V + E)

Let’s explore the detailed time and space complexity of the Prim’s Algorithm:



Time Complexity Analysis of Prim’s Algorithm:

Best Case Time Complexity: O(E log V)

Average Case Time Complexity: O((V + E) log V)



Worst Case Time Complexity: O((V + E) log V)

Auxiliary Space of Prim’s Algorithm:

The auxiliary space complexity of Prim’s Algorithm is O(V+E) for the priority queue used to store vertices and their key values during the algorithm’s execution.

Priority Queue/Min-Heap:

Visited Set:

Overall Complexity:

Article Tags :