What is the time complexity of Kruskal’s algorithm?

What is the time complexity of Kruskal’s algorithm?
A. O(log V)
B. O(E log V)
C. O(E$^{2}$)
D. O(V log E)
 
Answer: b
Explanation: Kruskal’s algorithm involves sorting of the edges, which takes O(E logE) time, where E is a number of edges in graph and V is the number of vertices. After sorting, all edges are iterated and union-find algorithm is applied. union-find algorithm requires O(logV) time. So, overall Kruskal’s algorithm requires O(E log V) time.
 

Tìm kiếm

Back
Top