Open In App

Time and Space Complexity Analysis of Kruskal Algorithm

Last Updated : 19 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Kruskal’s algorithm is a popular algorithm for finding the Minimum Spanning Tree (MST) of a connected, undirected graph. The time complexity of Kruskal’s algorithm is O(E log E), where E is the number of edges in the graph. The space complexity of Kruskal’s algorithm is O(V + E), where V is the number of vertices and E is the number of edges in the graph.

Complexity Kruskal’s Algorithm
Time Complexity O(E log E)
Space Complexity O(V + E)

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

Time Complexity of Kruskal’s Algorithm:

Best Case Time Complexity: O(E log E)

In the best case scenario, the graph’s edges are already sorted in non-decreasing order of weights. As a result, the sorting step can be performed in linear time. Hence, the time complexity remains O(E log E) due to the union-find operations and the space complexity is O(V + E).

Average Case Time Complexity: O(E log E)

The average case complexity of Kruskal’s algorithm is the same as the best and worst cases, O(E log E) for time complexity and O(V + E) for space complexity. This is because the algorithm’s performance is mainly determined by the sorting step, which dominates the overall complexity.

Worst Case Time Complexity: O(E log E)

In the worst case, where the edges are sorted in non-increasing order of weights, the sorting step will take O(E log E) time. The union-find operations also contribute to the time complexity. The space complexity remains O(V + E) regardless of the case due to the data structures used.

Auxiliary Space of Kruskal Algorithm:

The auxiliary space of Kruskal’s algorithm is the additional space required by the algorithm beyond the space needed to store the input graph. This space is used for data structures such as the priority queue and the disjoint-set data structure.

  • The priority queue is used to store the edges of the graph, sorted by their weight. The disjoint-set data structure is used to keep track of which vertices are in the same connected component.
  • The size of the priority queue is O(E), where E is the number of edges in the graph. The size of the disjoint-set data structure is O(V), where V is the number of vertices in the graph.

Therefore, the auxiliary space of Kruskal’s algorithm is O(E + V).


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads