I'm trying to find out what's the complexity of Kruskal's disjoint-set determining loops.
In Kruskal's
, we adding vertices into disjoint sets
and creating unions of these sets if we added an edge which has both vertices in different sets as far as I'm concerned. That's how we determining loops - if two vertices are already in one set, we don't add this edge.
How do we check whether a vertex is in the set? In my opinion, it is in O(n)
so Kruskal
would be at least in O(n^2)
+ sorting time of edges O(nlogn)
.
For example here SO Answer, which is my problem too, they say that it is possible to run Kruskal in O(V+E)
when you have just two types of edges. I get it, but I don't get the thing with disjoint sets, I think that it creates worse complexity.