I was doing an analysis of minimum spanning trees and was wondering how the sorting time would effect the overall time complexity of Kruskal's algorithm?
Example:
- If sorting can be done in
O(n log log n)
- If sorting can be done in
O(n)
Would the answer still remain O(e log n)
for both the cases or would it change?
The time of Kruskal algorithm is
O(e log e)
and its the time for sorting the edges. If you can do it in O(e), considering the rest of algorithm to find the minimum spanning tree is O (e log n), you haveO(e) + O(e log n)
. Sincee=O(n^2)
then the algorithm time would beO(n^2 log n)
orO(e log n)
. if sorting takes O(e log log e) with the same analysis the overall time would beO(e log log e)
.Details: The time for finding minimum spanning tree is calculated by the time you need for sorting edges and then a loop (e times) in which you remove each edge from the sorted list and examine if it connects two disjoint regions or not. (this check needs O (log n) ) and the time of the loop would be
O(e log n)
as mentioned above.using more sophisticated disjoint-set data structure to find and check disjoint regions the loop has O(E α(V)) time, where α is the extremely slowly growing inverse of the single-valued Ackermann function (WikiPedia)